问题
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