权限感知(图标)操作所有型号链接:怎么了? [英] permissions aware (icon) action links for all models: how?

查看:154
本文介绍了权限感知(图标)操作所有型号链接:怎么了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几种模式,对此我要显示操作链接(新,细节,编辑,删除),并只用于某些型号的对一些特定的一些常见的图标;当用户具有执行动作的权限,这些iconlinks必须只显示。权限由角色决定的,但我想他们的抽象,因此,明确需要的角色都写在只有一个地方。

I have several models, for which I want to show some common icons for action links (new, details, edit, delete) and some specific ones for certain models only; these iconlinks must only be showed when the user has permission to perform the action. Permissions are decided by roles, but I'd like to abstract them, so that the explicit needed roles are written in one place only.

我也想用同样的逻辑,以显示图标和保护的操作方法,这样,如果用于需要角色编辑lolcatz,现在我想将其更改为酒吧角色,我只需要改变的一件事。

I'd also like to use the same logic to show icons and to "protect" action methods, so that if Foo role used to be needed to edit lolcatz, and now I want to change it to Bar role, I only have to change one thing.

有实现这个方法很多,我如何进行把握。

There are many ways to implement this, and I'm unsure on how to proceed.

我可以写一个 ModelAction 类,负责决定的权限,链接,图标,文字的单个动作,有的 ModelActionsCollection 收集所有可能的操作为单一模式,让我可以写一个父类和几个递减的。

I could write a ModelAction class, responsible for deciding permissions, link, icon, text for a single action, and some ModelActionsCollection to gather all possible actions for a single model, so that I can write a parent class and several descending ones.

我的疑惑:


  • 我应该如何与关联 ModelActionsCollection 模式?我应该使用散列或一些静态类,如 SomeStaticClass.GetModelActionsCollection(someModel)?或 typeof运算(someModel)类名还是什么?

  • how should I associate models with ModelActionsCollection? Should I use a hash or some static class, like SomeStaticClass.GetModelActionsCollection(someModel)? or typeof(someModel), or "className" or what?

我应该怎么布置的方法呢?我应该写这样的:

how should I decorate methods? should I write something like:

[MyAuthorize("action", "model")]
public ActionResult action(...)

或其他什么东西?

什么情况下可以直接这些类方法的内部访问当前认证的用户,还是应该接收用户的参数?

is it okay to access to the current authenticated user directly inside these classes' methods, or should they receive user as parameter?

这班属于什么命名空间?他们是模特?佣工?还是什么?

what namespace this classes belong to? are they models? helpers? or what?

和,最后:有没有人做过这个都在一个可重用的方式

and, finally: has anybody already done all this in a reusable way?

推荐答案

我们做的正是这种

装饰用许可类型标志和CSS中的图标一个字符串你的动作
例如
[ActionModelPermission(typeof运算(ContactModel),PermissionTypes.Create | PermissionTypes.Edit,typeIcon类型端子)]

Decorate your action with a permission type flag and a string for the icon in css e.g. [ActionModelPermission(typeof(ContactModel), PermissionTypes.Create | PermissionTypes.Edit, "typeIcon typeContact")]

该ActionModelPermission,PermissionTypes和ContactModel是所有类在我们的项目。

The ActionModelPermission, PermissionTypes and ContactModel are all classes in our project.

然后,我们有我们自己的ActionLink帮助其找到提供从一个lambda方法并执行权限检查,并建立它与适当的CSS类的链接

Then we have our own ActionLink helper which finds the method from a lambda supplied and does the permission check, and builds the link with the appropriate css class on it

这篇关于权限感知(图标)操作所有型号链接:怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆