Sha256: f0b6d46b1735ce7e5309a63308982f66063e957a0df7b8f5f35f53231715526a

Contents?: true

Size: 636 Bytes

Versions: 46

Compression:

Stored size: 636 Bytes

Contents

module Itsf::Backend
  class Service::BasePolicy
    attr_reader :user, :service

    def initialize(user, service)
      @user = user
      @service = service
    end

    def index?
      authorize_with_rbac(user, service, __method__)
    end

    def invoke?
      authorize_with_rbac(user, service, __method__)
    end

    def call?
      invoke?
    end

    private

    def authorize_with_rbac(user, service_class, method_name)
      permission_identifier = "#{service_class.name.underscore}/#{method_name.to_s.chomp('?')}"
      user.respond_to?(:allowed_to?) ? user.allowed_to?(permission_identifier) : true
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
itsf_backend-5.0.0.pre app/policies/itsf/backend/service/base_policy.rb
itsf_backend-4.2.3 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-4.2.2 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-4.2.1 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-4.2.0 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-4.0.1 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-4.0.0 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-3.1.1 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-3.1.0 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-3.0.7 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-3.0.6 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-3.0.5 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-3.0.4 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-3.0.3 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-3.0.2 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-3.0.1 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-3.0.0 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-2.2.1 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-2.2.0 app/policies/itsf/backend/service/base_policy.rb
itsf_backend-2.1.0 app/policies/itsf/backend/service/base_policy.rb