I am currently developing a sharepoint webpart to display a private discussion board. The discussion can only be viewed by limitted users. The following allowed users as of now could be: Site Collection Owner, Discussion Board Members, Discussion Board Owner.
The way I setup the security of the webpart is by getting all the users and check if they belong to the said allowed persons in the discussion board.
My logic seems to be working right now but, the concern here of my client is: What if in the future they will change the settings or security of the discussion board and I might no longer be around to fix the code of the webpart such that the settings and security of the webpart will sync to the discussion board? My idea as of now is, instead of developing a code that will copy the settings and security of the discussion board and apply it to the webpart, I will point the settings and security of the webpart right directly to the discussion board. My question right now is, would this be possible?
Please see the attached pic to have a better view of what I wanted to happen.
Hi I have fixed the problem!
this word does the thing "DoesUserHavePermissions"... here is my code snippet
try
{
string strListUrl = "http://MySite.com/List/MyDiscussion/AllItems.aspx";
SPUser objCurrentUser = SPContext.Current.Web.CurrentUser;
SPSite objSite = new SPSite(SPContext.Current.Web.Url);
SPWeb objWeb = objSite.OpenWeb();
SPList objList = objWeb.Lists[strListUrl];
if(!objList.DoesUserHavePermissions(objCurrentUser,SPBasePermissions.EditListItems)){
throw new UnauthorizedAccessException("You are not authorized to view this discussion!");
}
}
catch(UnauthorizedAccessException uae){
/// some exception handling codes here
}
@djeeg: thanks for the help! 1 vote for you! :)