give permissions to backend Pages page
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.
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
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();
Hello Phil,
We sent a reply to you in the other thread you opened here.
Regards,
Ivan Dimitrov
the Telerik team
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.
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"
;
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);
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.
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
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);
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