[英]Add custom user roles spree 1.3.1
I am using spree 1.3.1 and Devise gem for authentication and i need to add a user_role called as " partner " who can see orders in admin area but can't create/edit/update/delete any of the orders. 我正在使用spree 1.3.1和Devise gem进行身份验证,我需要添加一个名为“ partner ”的user_role ,该用户可以在管理区域中查看订单,但无法创建/编辑/更新/删除任何订单。
Thanks in advance 提前致谢
Having app/models/partner_ability.rb
file. 具有app/models/partner_ability.rb
文件。
Then use the following role based read
permissions for role partner
- 然后对角色partner
使用以下基于角色的read
权限-
class PartnerAbility
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.has_role? "partner"
can :read, Product
end
end
end
Also add the following after that to config/initializers/spree.rb
- 然后在config/initializers/spree.rb
添加以下config/initializers/spree.rb
-
Ability.register_ability(PartnerAbility)
In db/seed.rb file we can directly add admin user in spree..
for example
puts 'SETTING UP DEFAULT USER LOGIN'
user1 = User.create! :title => 'Mr', :first_name => 'Jack', :last_name => 'Jackson', :email => 'jack@g.com', :password => '123qwe', :password_confirmation => '123qwe', :phone => '123452345'
puts 'New user created: ' << user1.first_name
user2 = User.create! :title => 'Mr', :first_name => 'Sev', :last_name => 'Raj', :email => 'sa@g.com', :password => '123qwe', :password_confirmation => '123qwe', :phone => '123452345'
puts 'New user created: ' << user2.first_name
puts 'New user created: ' << user4.first_name
user2.add_role :admin
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.