give permissions to backend Pages page

Posted by Community Admin on 03-Aug-2018 23:24

give permissions to backend Pages page

All Replies

Posted by Community Admin on 31-Jan-2011 00:00

I need to programatically permit a role to view the Pages backend page.   This is the page that displays a list of pages.  The SF gui takes you to this page when you are on the Dashboard page and you click "Pages" at the top where the menu words are:
Dashboard  Pages  Content  Design  Administration  Analytics

Can you send me or direct me to sample code on how to do this?
Thanks.

Posted by Community Admin on 01-Feb-2011 00:00

Hi Phil,

Please take a look at Secured Object - extensions. There is entire "Permissions" section in the developer manual that will help.

All the best,
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

Posted by Community Admin on 02-Feb-2011 00:00

I am using the code in the box to try to give Modify permission to a role.  (As you may recognize since you are working w me on that)   Regarding THIS thread, I have been trying to figure out what settings to change, to give a role permission so get into the Pages list* and I have not been able to figure out how to do that.  I suppose I change the SecurityConstants(?).   Thanks.

        var myPageManager = PageManager.GetManager();
        var fluent = App.WorkWith();
        var pgFacade = fluent.Page(); //
// I have verified that this guid gets the page that I want
        var pG = new Guid("6DF1E778-A011-4DF1-8B2E-9CD59D2686E2");
// I get a PageNode, just like your code snippet gets
        PageNode pn = pgFacade.PageManager.GetPageNodes()
            .Where(p => p.Id == pG).FirstOrDefault();
  
        var rm = RoleManager.GetManager();
        var objRole = rm.GetRole("theRole");
  
        string sn = SecurityConstants.Sets.Pages.SetName;
        var thePermission = myPageManager.CreatePermission(sn, pn.Id, objRole.Id );
        thePermission.GrantActions(false, SecurityConstants.Sets.Pages.Modify);
  
        pn.Permissions.Add(thePermission);
        myPageManager.SaveChanges();

*From what I understand I have to do this so that when the user in that role goes to the Dashboard, they will see the Pages link and they can then see the page they want to edit in the Pages list.  When I use the gui, I achieve this by going to Administration/ BackendPages/ then edit the Permissions for the Pages page.

Posted by Community Admin on 11-Feb-2011 00:00

Hello Phil,

We sent a reply to you in the other thread you opened here.

Regards,
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

Posted by Community Admin on 15-Feb-2011 00:00

Thanks.  That other thread was pretty helpful, but in this thread I need help with what to set in code, so that users in a specific role will be able to see the Pages list, so they can select their page and edit it.

When I use the gui, I achieve this by going to Administration/ BackendPages/ then edit the Permissions for the Pages page.

How do I do this in code?

I have explored  SecurityConstants.Sets.Pages.... and  SecurityConstants.Sets.Backend...   but have not been able to figure this out.

Thanks again.

Posted by Community Admin on 17-Feb-2011 00:00

Hi Phil,

Below is a list with the permission sets  that you can use

/// Pages permission set name
public const string SetName = "Pages";
 
/// View action name
public const string View = "View";
 
/// Create action name
public const string Create = "Create";
 
/// Modify action name
public const string Modify = "Modify";
 
 
/// EditContent action name
public const string EditContent = "EditContent";
 
/// ManageControls action name
public const string CreateChildControls = "CreateChildControls";
 
/// Delete action name
public const string Delete = "Delete";
 
 
/// ChangeOwner action name
public const string ChangeOwner = "ChangeOwner";
 
/// ChangePermissions action name
public const string ChangePermissions = "ChangePermissions";

1. You need to get the backend Pages page
2. You need to set permissions over it.

sample

Permission p = this.PageManager.CreatePermission(SecurityConstants.Sets.Pages.SetName, backendNode.Id, SecurityManager.BackEndUsersRole.Id);
p.GrantActions(false, SecurityConstants.Sets.Pages.View);
backendNode.Permissions.Add(p);

The backenNode.Id should be SiteInitializer.PagesNodeId -

All the best,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 17-Feb-2011 00:00

That was some helpful guidance.  Thanks.
Problem:
Lines 6-9 of the following code returns null - theBackPermission == null
So the next block, 10-14 runs.  However it chokes on line 14, SaveChanges(), saying:

SQLException: Cannot insert duplicate key row in object 'dbo.sf_permissions' 
with unique index 'idx_sf_permissions'.

01.const string snBack = SecurityConstants.Sets.Pages.SetName;
02.var backendNodeId = SiteInitializer.PagesNodeId;
03.PageNode pnBack = myPageManager.GetPageNodes().Where(p => p.Id == backendNodeId).FirstOrDefault();
04.if (pnBack.InheritsPermissions) myPageManager.BreakPermiossionsInheritance(pnBack);
05. 
06.Permission theBackPermission = pnBack.Permissions.Where(p =>
07.        p.SetName == snBack &&
08.        p.ObjectId == backendNodeId &&
09.        p.PrincipalId == principalId).FirstOrDefault();
10.if (theBackPermission == null)
11.
12.    theBackPermission = myPageManager.CreatePermission(snBack, backendNodeId, principalId);
13.    pnBack.Permissions.Add(theBackPermission);
14.    myPageManager.SaveChanges();
15.

I think that Permissions.Where() (line 6) is getting something different than CreatePermissions()  (line 12) is creating.

For fun, I stopped the code in debug, on line 14, and looked at all the items in pnBack.Permissions, and compared them with the theBackPermission object.  Nothing in pnBack.Permissions, was the same as theBackPermission.

Please advise how I can check for the permisssion and then and the permission I need correctly.

Thanks

Posted by Community Admin on 22-Feb-2011 00:00

Hello Phil,

The error says that you have this permission already set for the principal. Can you observer pnBack.Permissions before making the query to see all permissions?

Kind regards,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 15-Sep-2011 00:00

I have the same problem, create a new module based on the example of creating a module of products ... which adds the interface module from appending the code ... the code up but I need to add permissions to a user who has a role of a specific country ... I've seen the example and I implemented the code described by telerik, but I can not make it work, it falls to insert the new license .... which really should put the code within the same code to create or load module itself ... I've noticed that when creating the module from the dashboard in the persmisos Administration works ... this is a bit of code that generates:

  string [] roles = "RoleName";
             PageManager PageManager PageManager = new ();
             var rm = RoleManager.GetManager ();
             var rm.GetRole objRole = ("Peru");
             var pageManager.GetPageNode parentPage = (new Guid ("09A80073-E817-4E7B-A8F5-149574868CAD"));
             objRole.Id roleId = var;


             Telerik.Sitefinity.Security.Model.Permission parentPage.GetActivePermissions peruanoPermiss = (). Where (p => == p.PrincipalId p.ObjectId roleId & & & & p.SetName == == parentPage.Id SecurityConstants.Sets.Pages.SetName ). FirstOrDefault ();
             if (peruanoPermiss == null)
            
                 peruanoPermiss = pageManager.CreatePermission (SecurityConstants.Sets.Pages.SetName, parentPage.Id, roleId);
                 parentPage.Permissions.Add (peruanoPermiss);
            
             peruanoPermiss.GrantActions (true, SecurityConstants.Sets.Pages.View);

 


 


Posted by Community Admin on 17-Sep-2011 00:00

Hi Alejandro,

There is an issue with the logical operators that you use several times

Where (p => == p.PrincipalId p.ObjectId roleId & & & & p.SetName == == parentPage.Id SecurityConstants.Sets.Pages.SetName ). FirstOrDefault ();

Also after the permissions are granted for a given role you can check if they are persisted. So after you execute your call get the permissions again for the principal and ISecuredObject and see the returned value.

Best wishes,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed