Sha256: c582c7ab984a8b13db94a07fb2836c3b3c87f328ec62218fecb6b12726c3bfca

Contents?: true

Size: 789 Bytes

Versions: 5

Compression:

Stored size: 789 Bytes

Contents

module Spree
  Ability.class_eval do

    def initialize(user)
      self.clear_aliased_actions

      alias_action :edit, :to => :update
      alias_action :new, :to => :create
      alias_action :new_action, :to => :create
      alias_action :show, :to => :read
      alias_action :delete, :to => :destroy

      user ||= Spree::User.new

      user_roles(user).each do |role|
        ability(role, user)
      end

      Ability.abilities.each do |clazz|
        ability = clazz.send(:new, user)
        @rules = rules + ability.send(:rules)
      end
    end

    def user_roles(user)
      (roles = user.roles.includes(:permissions)).empty? ? Spree::Role.default_role.includes(:permissions) : roles
    end

    def ability(role, user)
      role.ability(self, user)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_admin_roles_and_access-1.3.0 app/models/spree/ability_decorator.rb
spree_admin_roles_and_access-1.2.1 app/models/spree/ability_decorator.rb
spree_admin_roles_and_access-1.2.0 app/models/spree/ability_decorator.rb
spree_admin_roles_and_access-1.1.0 app/models/spree/ability_decorator.rb
spree_admin_roles_and_access-1.0.0 app/models/spree/ability_decorator.rb