自定义模块中的 Orchard 权限
所以我创建了我的第一个 Orchard 模块,它本质上只是管理面板中的 CRUD,并且有一个可供公众使用的前端表单。现在我需要在管理面板中为不同的用户角色提供不同级别的访问权限。我已经很好地创建了“管理员”用户,但现在我遇到了权限较低的用户的麻烦,他们只能看到记录的子集。
问题是我不知道从哪里开始。我很乐意在我的列表屏幕上说: if (UserRole == "SomeRestrictedRole") Select.Where("however we limit");
- 但我不知道如何访问UserRole(我对 .NET MVC 也相当陌生)。
我认为正确的解决方案是扩展 IPermissions 或类似的东西?但同样,我找不到任何教程或文档来指导我正确的方向。
以下是我到目前为止读过的文档:
http ://docs.orchardproject.net/Documentation/Creating-a-module-with-a-simple-text-editor
http://docs.orchardproject.net/Documentation/Understanding-data-access
http://docs.orchardproject.net/Documentation/Managing-users-and-roles
http://docs.orchardproject.net/Documentation/Understanding-permissions
任何建议将不胜感激!
So I've created my first Orchard module, which is essentially just a CRUD in the admin panel, with a front-end form available to the public. Now I need to give different levels of access to different user roles in the admin panel. I've created the "admin" users fine, but now I have trouble with the less privlidged users, who can only see a subset of the records.
The problem is I have NO IDEA where to start. I would be happy to just say on my List screen: if (UserRole == "SomeRestrictedRole") Select.Where("however we restrict");
- but I don't know how to access the UserRole (I'm also fairly new to .NET MVC).
I think the PROPER solution would be to extend IPermissions or something like that? But again, I can't find any tutorials or docs to point me in the right direction.
Here are the docs I have read so far:
http://docs.orchardproject.net/Documentation/Creating-a-module-with-a-simple-text-editor
http://docs.orchardproject.net/Documentation/Understanding-data-access
http://docs.orchardproject.net/Documentation/Managing-users-and-roles
http://docs.orchardproject.net/Documentation/Understanding-permissions
Any advice would be much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,不要根据角色限制访问,而是根据权限限制访问。查看任何 Permissions.cs 以获取实现示例。然后搜索其中声明的权限以查看强制执行它们的示例。这真的很简单,你就会看到:)
Right, don't restrict access based on roles, but rather on permissions. Look at any Permissions.cs for examples of implementation. Then search for the permissions declared in there to see examples of enforcing them. It's really easy, you'll see :)