首页 文章

Spree自定义/扩展用户角色和权限

提问于
浏览
3

我试图在Spree中指定一些自定义角色,例如角色'client',并扩展权限以访问此角色的admin部分 .

该用户只能访问该用户创建的产品 . 概念是让具有角色“客户”的用户仅管理产品和其他特定模型 .

首先,我添加了CanCan插件,并在role_ability.rb中定义了RoleAbility类

就这篇文章:Spree Custom Roles Permissions

class RoleAbility
  include CanCan::Ability

  def initialize(user)
    user ||= User.new
    if user.has_role? 'admin'
        can :manage, :all
    elsif user.has_role? 'client_admin'
      can :read, Product
      can :admin, Product
    end
  end
end

将其添加到初始化程序:config / initializers / spree.rb

Ability.register_ability(RetailerAbility)

还扩展了admin_products_controller_decorator.rb:app / controllersadmin_products_controller_decorator.rb

Admin::ProductsController.class_eval do
    def authorize_admin
        authorize! :admin, Product
        authorize! params[:action].to_sym, Product
    end
end

但我收到闪存消息'授权失败'

试图找到一些运气,我提到了以下链接

定制狂欢角色的github要点:https://gist.github.com/1277326

这是我面临的类似问题:http://groups.google.com/group/spree-user/browse_thread/thread/1e819e10410d03c5/23b269e09c7ed47e

一切努力都是徒劳的......

任何指针高度赞赏?

提前致谢 .

1 回答

  • 4

    终于找到了 .

    经过一些仔细的研究后发现,spree 1.1.1通过在每个类中添加“Spree”模块来改变了类,这导致了像“spree / admin / overview”这样的url,之前是“admin / overview” .

    这对我有用,我能够控制角色的权限 .

相关问题