Ticket

Updating permissions via code not changing "Effective"

Thought I would try posting this over here to see if anyone has ideas...

In a custom application I'm working on, I'm changing permissions for the Anonymous role via code. The code I'm using is derived from the Orchard.Roles module and works to change the "Allow" permission for the role, but the "Effective" permission doesn't seem to get updated. If I then go into the UI and click "Save" on the role, the "Effective" permissions are updated.

Is there something I can do via code to affect both the "Allow" AND "Effective" permissions? I would have thought updating the role would affect both. Here's the code:

var anonymousRole = roleService.GetRoleByName("Anonymous");
List<string> anonymousPermissions = roleService.GetPermissionsForRoleByName("Anonymous").ToList();

if (privacyLevel == "medium" || privacyLevel == "high") {
    anonymousPermissions.Remove("AccessFrontEnd");
    anonymousPermissions.Remove("ViewContent");
    anonymousPermissions.Remove("AddComment");
}
else {
    anonymousPermissions.Add("AccessFrontEnd");
    anonymousPermissions.Add("ViewContent");
    anonymousPermissions.Add("AddComment");
}

roleService.UpdateRole(anonymousRole.Id, anonymousRole.Name, anonymousPermissions);

Any suggestions on what I might be doing wrong? Thanks.

Re: Updating permissions via code not changing

Find out where the effective permission is inherited from, and change that.

Tuesday, December 9, 2014 10:41:52 PM bybleroy
  • bleroy
  • Lv. 08 Rookie
  • Total EXP: 527

Re: Updating permissions via code not changing

That's what's tripping me up on this. Effective permissions is just an IEnumerable that is passed to the view in a ViewModel for display purposes. When the Permissions are submitted, the only thing that is sent anywhere is a List of Permission names to the UpdateRole method which is exactly what I'm doing. There isn't anything that specifically sets Effective permissions, yet when I view the Role after my process runs, the Effective permissions are not changed even though the Allow permissions are. Submitting the page from the UI updates the Effective permissions, but all that does is run the UpdateRole method with the same parameters I am in my code.

I'll keep digging, but this one is really throwing me for a loop.

Wednesday, December 10, 2014 12:41:32 AM bypsenechal

Re: Updating permissions via code not changing

I think I may have found a solution. So far, it appears that adding:

_shellSettingsManager.SaveSettings(tenant);

after I update the permissions resolves the issue. I'll keep testing it though to make sure.

Wednesday, December 10, 2014 1:08:34 AM bypsenechal

Re: Updating permissions via code not changing

That's what effective permissions mean: they are the results of the addition of all the permissions. You cannot set effective permissions, in the same way that you can't set the value of a + b. You can set a, you can set b, and those are the only ways to set (a + b), but you cannot say var a + b = 42. That just doesn't make any sense.

Wednesday, December 10, 2014 2:02:41 AM bybleroy
  • bleroy
  • Lv. 08 Rookie
  • Total EXP: 527

Post a reply

You need to be signed in to post a reply.

Sign In