Add custom user roles spree 1.3.1

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 05:07:42

问题


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.

Thanks in advance


回答1:


Having app/models/partner_ability.rb file.

Then use the following role based read permissions for role partner -

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 -

Ability.register_ability(PartnerAbility)



回答2:


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


来源:https://stackoverflow.com/questions/14338237/add-custom-user-roles-spree-1-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!