Sha256: d29e23de3ea8df1a0c543b57353c31bed5df135638d3f34d682be022c850203b
Contents?: true
Size: 1.8 KB
Versions: 1
Compression:
Stored size: 1.8 KB
Contents
require "ingress/permissions_repository" require "ingress/copy_permissions_repository_into_role" require "ingress/build_permissions_repository_for_role" module Ingress class Permissions class << self def permissions_repository @permissions_repository ||= PermissionsRepository.new end def inherits(permissions_class) role_identifier = :dummy if permissions_class @permissions_repository = permissions_repository.merge( Services::CopyPermissionsRepositoryIntoRole.perform(role_identifier, permissions_class.permissions_repository), ) end end def define_role_permissions(role_identifier = nil, permissions_class = nil, &block) if role_identifier.nil? role_identifier = :dummy end if permissions_class @permissions_repository = permissions_repository.merge( Services::CopyPermissionsRepositoryIntoRole.perform(role_identifier, permissions_class.permissions_repository), ) end if block_given? @permissions_repository = permissions_repository.merge(Services::BuildPermissionsRepositoryForRole.perform(role_identifier, &block)) end end end attr_reader :user def initialize(user) @user = user end def can?(action, subject) user_role_identifiers.any? do |role_identifier| rules = self.class.permissions_repository.rules_for(role_identifier, action, subject) cannot_match = rules.reject(&:allows?).any? do |rule| rule.match?(action, subject, user) end break false if cannot_match rules.select(&:allows?).any? do |rule| rule.match?(action, subject, user) end end end def user_role_identifiers [] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ingress-0.2.0 | lib/ingress/permissions.rb |