简体   繁体   中英

Spree commerce with rails custom user roles

I am trying to add a user role of salesRep who can order products from admin side on behalf of users by selecting the users from the dropdown(same as admin). I am using spree commerce in rails 5. I have ability_decorator at app/models/spree/ability_decorator.rb

class AbilityDecorator
     include CanCan::Ability
     def initialize(user)
     if user.respond_to?(:has_spree_role?) && user.has_spree_role?  ('sales_rep')
        can [:admin, :manage], Spree::Order
        can [:admin, :index, :show], Spree::Product   
     end
   end
end

Spree::Ability.register_ability(AbilityDecorator)

Though there is no error, I am able to view only the order tab and product tab as expected. But the Order tab displays only selected information. It does not display customer dropdown to select customer or customer details like email, password, address etc which is all present in admin login. What changes should I make to have the exact functionality like admin login?

This is correct code for spree custom user roles.

class AbilityDecorator
     include CanCan::Ability
     def initialize(user)
     if user.respond_to?(:has_spree_role?) && user.has_spree_role?('admin_store')
        can [:admin, :manage], Spree::Order
        can [:admin, :index, :show], Spree::Product   
     end
   end
end

Spree::Ability.register_ability(AbilityDecorator) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM