添加自定义用户角色狂欢 1.3.1 [英] Add custom user roles spree 1.3.1

查看:47
本文介绍了添加自定义用户角色狂欢 1.3.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 spree 1.3.1Devise gem 进行身份验证,我需要添加一个名为合作伙伴"的user_role" 可以在管理区域查看订单但不能创建/编辑/更新/删除任何订单.

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.

提前致谢

推荐答案

拥有 app/models/partner_ability.rb 文件.

然后使用以下基于角色的read权限给角色partner -

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

config/initializers/spree.rb 之后添加以下内容 -

Also add the following after that to config/initializers/spree.rb -

Ability.register_ability(PartnerAbility)

这篇关于添加自定义用户角色狂欢 1.3.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆