狂欢自定义角色权限 [英] Spree Custom Roles Permissions

查看:88
本文介绍了狂欢自定义角色权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

这篇关于狂欢自定义角色权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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