Sha256: 131b151267814ff02b0b89ba83cbae3eb88df9685593055ae274ccff9e155d61

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module CanTango
  module PermitEngine
    module Executor
      class Base < Abstract
        # execute the permit
        def execute!
          role_execution
          #role_group_execution
        end

        # only execute the permit if the user has the role of the permit or is for any role      
        def role_execution
          permit? if permit_for_user_role? || permit_for_user_group?
        end

        def permit_for_user_role?
          subject_in_role? || role == :any
        end

        def role_group_execution
          # could also use #user.is_member_of?
          permit? if permit_for_user_group?
        end

        def permit_for_user_group?
          subject_in_role_group? || false
        end

        protected

        def subject_in_role?
          return subject.send(has_role_meth, role) if subject.respond_to? has_role_meth
          return subject.send(list_role_meth, role).include? role if subject.respond_to? has_role_meth
          false
        end

        def subject_in_role_group?
          return subject.send(has_role_group_meth, role) if subject.respond_to? has_role_group_meth
          return subject.send(list_role_group_meth).include? role if subject.respond_to? list_role_group_meth
          false
        end

        include CanTango::Helpers::RoleMethods

        def role
          permit.role
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cantango-0.8.0 lib/cantango/permit_engine/executor/base.rb