Sha256: 256d1e6846781a3a4c9b02fd1e304e3198e1702d413dbae8689f5dd06fb0bffe

Contents?: true

Size: 844 Bytes

Versions: 1

Compression:

Stored size: 844 Bytes

Contents

module Outpost
  module Model
    module Authorization
      extend ActiveSupport::Concern

      included do
        has_many :user_permissions
        has_many :permissions, through: :user_permissions
      end
      # Check if a user can manage the passed-in resource(s)
      #
      # If multiple resources are passed in, a user must be
      # allowed to manage ALL of them in order for this to
      # return true.
      #
      # Constants must be passed in.
      #
      def can_manage?(*resources)
        self.is_superuser? or (allowed_resources & resources) == resources
      end

      #
      
      def allowed_resources
        @allowed_resources ||= begin
          p = self.is_superuser? ? Permission.all : self.permissions
          p.map { |p| p.resource.safe_constantize }.compact
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
outpost-cms-0.0.3 lib/outpost/model/authorization.rb