Forums

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity 3.x: Developing with Sitefinity > Set page permissions programmatically

Set page permissions programmatically

  • Jenn Bohm avatar

    Posted on Mar 12, 2010 (permalink)

    I am trying to use SecurityManager.SetPermissions to set permissions on a page, and I'm not sure how to use the parameters "grant" and "deny". I see they are integers, but what kind of values should they have? I'm looking for an example of the use of this method, and can't find anything.

    Reply

  • Answer Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Mar 14, 2010 (permalink)

    Hello Jenn Bohm,

    Below is a sample code that illustrates how to set permissions for a given page.

    var manager = new CmsManager();
    ICmsPage page = (ICmsPage)manager.GetPage(new Guid("8f48d010-9e87-4201-9a89-06b65ddded8a"), true);
    ISecured secured = page as ISecured;
    string[] rolenames = {"test"};
     secured.SetPermissions(CrudRights.View, CrudRights.Delete, rolenames);


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

    Reply

  • Jenn Bohm avatar

    Posted on Mar 23, 2010 (permalink)

    Thank you!

    Reply

  • Jenn Bohm avatar

    Posted on Mar 26, 2010 (permalink)

    So I have more questions about this. In a call to SetPermissions, I can pass one CrudRights to grant them permission on, and one to deny them permission on. I must be missing something here, but I don't see how to do a couple simple-seeming things:
    1. deny ALL rights to one set of roles
    2. grant view rights and deny ALL OTHER rights to another set of roles

    If I don't want to grant ANY rights, and want to deny ALL rights to a particular role, what would I pass as the grant argument? I had hoped there would be a "CrudRights.All" or some such thing, but only saw values for individual rights (ChangePermissions, Create, Delete, Modify, and View)
    When I used SetPermissions(CrudRights.View, CrudRights.Delete, roles), then viewed the page in the cms dashboard, I saw that in the Permissions section for the page in question, View had "grant" checked, and Delete had "deny" checked, and neither "grant" nor "deny" was checked for any of the other rights, and for all roles other than that for which I wanted to grant view rights only had nothing checked for any of the rights.

    I know this shouldn't be that hard to do, but somehow I'm just not getting it.

    edit: it looks like perhaps to combine multiple rights, I should bitwise "or" them? that's what I'm about to try next. not sure what I should be putting in for the "grant" argument if there's nothing I want to grant, though. trying zero...

    Reply

  • Answer Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Mar 28, 2010 (permalink)

    Hello Jenn Bohm,

    You can deny all permissions to a role/s if you pass "0" to the first and second parameter of SerPermissions method

    secured.SetPermissions(0, 0, rolenames);

    You could also use conditions as shown below

    secured.SetPermissions(0, CrudRights.Delete | CrudRights.View, rolenames);

    To grant only view pass CrudRights.View to the first parameter of SetPermissions and "0" for the second.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

    Reply

  • Jenn Bohm avatar

    Posted on Mar 29, 2010 (permalink)

    It looks like this worked, thanks! ^_^

    Reply

  • Register for webinar
Skip Navigation LinksHome / Developer Network / Forums / Sitefinity 3.x: Developing with Sitefinity > Set page permissions programmatically