狂欢自定义角色权限

编程入门 行业动态 更新时间:2024-10-09 08:37:13
本文介绍了狂欢自定义角色权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在狂欢特定权限内赋予一些自定义角色. 无法在任何地方找到这个答案

I am trying to give some custom roles within spree specific permissions. Cant find this answer anywhere

role_ability.rb

role_ability.rb

class RoleAbility include CanCan::Ability def initialize(user) user || User.new # for guest if user.has_role? "admin" can :manage, :all elsif user.has_role? "retailer" can :manage, Product else can :read, :all end end end

我认为这可能是一个流行的想法,即让具有经理"角色的用户仅管理产品和其他某些型号...

I thought this might be a popular idea, of letting a user with role 'manager' manage only products and other certain Models...

如果我更改

elsif user.has_role? "retailer" can :manage, Product

elsif user.has_role? "retailer" can :manage, :all

它可以按预期运行...我可以访问所有管理区域

It works as expected... I can access all of the admin area

我只希望零售商"能够管理产品! ;)

I only want the "Retailer" to be able to :manage Products tho!! ;)

管理员"只是与用户相关联的角色,即所有角色均为用户".

"admin" is only a role associated with a user, ie all roles are Users.

您可能会看到它的去向,零售商可以注册并出售自己的商品.这就是目标.

You can probably see where this is going, Retailers can sign up and sell items of their own.. well thats the goal.

任何指针?

推荐答案

spree_auth_devise中有一种本地方法可以做到这一点.它没有记录,但现在是.

There is a native way in spree_auth_devise to do this. It was not documented, but now is.

github/spree/spree_auth_devise 部分:在现有的Rails应用程序中使用"

github/spree/spree_auth_devise Section: "Using in an existing Rails application"

更多推荐

狂欢自定义角色权限

本文发布于:2023-10-23 02:45:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519516.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   角色   权限

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!