Adding custom user roles spree 1.3.1

I am using spree 1.3.1 and Devem gem for authentication and I need to add a user_role called " partner " that can see orders in the admin area but cannot create / edit / update / delete any orders.

Thank you in advance

0


source to share


2 answers


Has a file app/models/partner_ability.rb

.

Then use the following role based permissions read

for the 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)

      

+1


source


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

      



-1


source







All Articles