简体   繁体   English

使用Rails自定义用户角色进行狂欢交易

[英]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). 我正在尝试添加salesRep的用户角色,该角色可以通过从下拉列表中选择用户(与admin相同)来代表用户从管理员那边订购产品。 I am using spree commerce in rails 5. I have ability_decorator at app/models/spree/ability_decorator.rb 我正在使用Rails 5中的Spree Commerce。我在app / models / spree / ability_decorator.rb中具有Capacity_decorator

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) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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