I. Foreground Permissions
1: only visible to you
First, make sure that the view page by others and view all content corresponding to the user are not selected on the role settings page. Note: we must first set the permissions for anonymous and authenticated, and these two permissions are not selected.
In this way, we can reach the entire site, and we can only see our own things, as shown below:
However, if you log on with full permissions such as admin, it should be like this:
2: only a role is allowed to see
Similarly, 1.
Ii. Custom Permissions
First, create the file permissions in the root directory of the module:
Public class permissions: ipermissionprovider {
Public static readonly permission manageblogs = new permission {description = "manage blogs for others", name = "manageblogs "};
Public static readonly permission manageownblogs = new permission {description = "manage own blogs", name = "manageownblogs", impliedby = new [] {manageblogs }};
Public static readonly permission publishblogpost = new permission {description = "Publish or unpublish blog post for others", name = "publishblogpost", impliedby = new [] {manageblogs }};
Public static readonly permission publishownblogpost = new permission {description = "Publish or unpublish own blog post", name = "publishownblogpost", impliedby = new [] {publishblogpost, author }};
Public static readonly permission editblogpost = new permission {description = "Edit blog posts for others", name = "editblogpost", impliedby = new [] {publishblogpost }};
Public static readonly permission editownblogpost = new permission {description = "Edit own blog posts", name = "editownblogpost", impliedby = new [] {editblogpost, publishownblogpost }};
Public static readonly permission deleteblogpost = new permission {description = "delete blog post for others", name = "deleteblogpost", impliedby = new [] {manageblogs }};
Public static readonly permission deleteownblogpost = new permission {description = "delete own blog post", name = "deleteownblogpost", impliedby = new [] {deleteblogpost, manageownblogs }};
Public static readonly permission metalistblogs = new permission {impliedby = new [] {editblogpost, publishblogpost, deleteblogpost}, name = "metalistblogs "};
Public static readonly permission metalistownblogs = new permission {impliedby = new [] {editownblogpost, publishownblogpost, deleteownblogpost}, name = "metalistownblogs "};
Public Virtual feature {Get; set ;}
Public ienumerable <permission> getpermissions (){
Return new [] {
Manageownblogs,
Manageblogs,
Editownblogpost,
Editblogpost,
Publishownblogpost,
Publishblogpost,
Deleteownblogpost,
Deleteblogpost,
};
}
Public ienumerable <permissionstereotype> getdefasterstereotypes (){
Return new [] {
New permissionstereotype {
Name = "Administrator ",
Permissions = new [] {manageblogs}
},
New permissionstereotype {
Name = "Editor ",
Permissions = new [] {publishblogpost, editblogpost, deleteblogpost}
},
New permissionstereotype {
Name = "moderator ",
},
New permissionstereotype {
Name = "author ",
Permissions = new [] {manageownblogs}
},
New permissionstereotype {
Name = "contributor ",
Permissions = new [] {editownblogpost}
},
};
}
}
Second, we need to set permissions for the service in the controller, such:
public AdminController(IMyService myService, IOrchardServices orchardServices) { _myService = myService; Services = orchardServices; }
...
Services.Authorizer.Authorize(Permissions.SomeModulePermission, T("Some operation failed"));
3. Obtain the role information of the currently logged-on user
Iv. Set permissions for the part
At this point, orchard has full control over explicit and functional permissions, including part parts on the page.
Refer:
Http://docs.orchardproject.net/Documentation/Developer-FAQ
Http://orchard.codeplex.com/discussions/547703
Http://orchard.codeplex.com/discussions/390754