Sha256: 9407221920c528643f109eb6259fb311462f60152c7c2e8872d625b0f9314cb9

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

module CanTango
  class PermitEngine < Engine
    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

3 entries across 3 versions & 1 rubygems

Version Path
cantango-0.8.6.1 lib/cantango/permit_engine/executor/base.rb
cantango-0.8.6 lib/cantango/permit_engine/executor/base.rb
cantango-0.8.5.1 lib/cantango/permit_engine/executor/base.rb