IPermissionProvider and Default Role

Topics: Administration, Core, Customizing Orchard, General
Dec 12, 2012 at 2:47 AM

Thank you all for viewing my post. I got a question, and I don't have any clue.

I have implemented the IPermissionProvider interface, and in the method GetDefaultStereotypes, I define a custom permission for a custom role and a default role. However, in the web interface "Edit Role" page, the permission is not effective for the custom role "CustomRole", but is in effective for the default role "Administrator".

public IEnumerable<PermissionStereotype> GetDefaultStereotypes() {
    return new[] {
        new PermissionStereotype {
            Name = "CustomRole",
            Permissions = new[] {CustomPermission}
        },
        new PermissionStereotype {
            Name = "Administrator",
            Permissions = new[] {CustomPermission}
        }
    };
}

For the custom role "CustomRole", I created it through admin web interface. Is there a way to create it in the code?

And my actual question is how to make the "CustomPermission" in effective by default for the "CustomRole"? So I don't need to select the "Allow" checkbox manually for each custom roles.

Many Thanks.

Dec 12, 2012 at 2:54 PM

In Orchard.Roles module, Orchard.Roles.DefaultRoleUpdater is responsible for update Default Stereotypes when a feature is Installing.

Maybe help.

Dec 13, 2012 at 6:05 AM
Edited Dec 13, 2012 at 6:05 AM

Thanks, that is very helpful. It let me make one step toward Orchard now.

Feb 2, 2013 at 12:45 PM
Hello, I have this problem:
During the installation only the "IPermissionProvider" implementations from "hardcoded"(Module.Setup: SetupService.cs, line 84) modules are resolved in "DefaultRoleUpdater" ctor. So, the "GetDefaultStereotypes" is not called for any other modules being installed via selected recipe.

For updating roles on module enable, i just updated "DefaultRoleUpdater":
    void IFeatureEventHandler.Enabling(Feature feature) {
        AddDefaultRolesForFeature(feature);
    }