Reputation: 3
I'm implementing a site using an extending Orchard CMS. My problem is when I try to assign Orchard's existings Permissions to custom Roles from a custom Recipe.
I'm doing this in my recipe:
<Roles>
<Role Name="Profesional" Permissions="AccessAdminPanel,EditOwnContent,DeleteOwnContent,ViewOwnContent,ManageOwnBlogs,EditOwnBlogPost,EditBlogPost,PublishOwnBlogPost,PublishBlogPost,DeleteOwnBlogPost" />
<Role Name="Manager" Permissions="AccessAdminPanel,PublishContent,DeleteContent" />
</Roles>
When I put the code before enabling the features some permissions seems to be overrided, because Blogs permissions disapear from Profesional role.
<Roles>
same above
</Roles>
<Feature enable="..." />
And when move the Roles tag to the end of my Recipe, the Permissions set by code on my custom modules get overridden by the ones at the end of the Recipe.
What's the problem here? Is there a better way to achieve my goal?
Upvotes: 0
Views: 779
Reputation: 741
Assigning a role in code is pretty straight forward by calling the Role Service from Orchard.Roles. Have a look at the Commands too, that way you willbe abel to see how to set Commands from your recipe as I think you got the idea of from exporting harcoded Roles...
Permissions can be added from a module too by just implementing IPermissionProvider. pretty much like any Orchard feature is available to you. Usually you will see a Permissions.cs in a module.
I have created Roles in Migrations and within an Event too.
If you are to use a recipe which so far have never used to set Roles and Permissions, I would use the Command element.
Have you had a look to Orchard.SetUp?
Enable any features you like and if YOUR Custom Modules do not handle the role creation use the Command Element in your recipe.
Which is what i would do if the Permissions you like to attach are from a non-custom Module.
Alternatively, since it seems you have some Company Rules at hand; you could create a module to abstract all that.
Hope it helps
Upvotes: 1