Skip to content

Instantly share code, notes, and snippets.

@charlesj
Created February 13, 2012 17:02
Show Gist options
  • Save charlesj/1818311 to your computer and use it in GitHub Desktop.
Save charlesj/1818311 to your computer and use it in GitHub Desktop.
public class EditWebpagePermission : IWebsitePermission
{
public bool HasOption
{
get { return true; }
}
public bool Check(Models.User user, System.Web.Mvc.ActionExecutingContext context)
{
//okay there are alot of things that need to be checked here.
//first, check to see if the user actually has this permission at all, without any options.
if (user.HasPermission(this.Name))
{
//okay, they have this permission, so they can access the webpages.
//I guess to check the option, that will be a different check?
return true;
}
else
{
//they don't have this permission.
return false;
}
}
public string Option { get; set; }
public string Description
{
get { return "Provides access to edit certain webpages"; }
}
public string Name
{
get { return "Edit Webpages"; }
}
public string OptionDescription
{
get { return "The folder where the user can edit"; }
}
public List<PermissionDropDown> DropDown
{
get {
var db = new KangarooContext();
var rtn = new List<PermissionDropDown>(); //okay, so this has to hold all webpage folders
var curr_folder = db.Folders.Where(f => f.Name == "Webpages").Single();
rtn.Add(new PermissionDropDown { Name = curr_folder.Path, Value = curr_folder.FolderId.ToString() });
return AddChildren(curr_folder, rtn);
}
}
private List<PermissionDropDown> AddChildren(Folder f, List<PermissionDropDown> work)
{
foreach (var child in f.Children)
{
work.Add( new PermissionDropDown { Name = child.Path, Value = child.FolderId.ToString() });
AddChildren(child, work);
}
return work;
}
public static bool CheckOption(Models.User user, Models.Folder folder)
{
var option = Convert.ToInt32(user.GetPermissionOption("Edit Webpages"));
if (folder.FolderId == option || folder.FolderIsAncestor(option))
return true;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment