Class: Sipity::Policies::SipPolicy

Inherits:
BasePolicy show all
Defined in:
app/policies/sipity/policies/sip_policy.rb

Overview

Responsible for enforcing access to a given Sipity::Sip.

This class answers can I take the given action based on the user and the sip.

See Also:

  • gem](http://rubygems.org/gems/pundit) for more on object oriented authorizaiton.

Defined Under Namespace

Classes: Scope

Instance Attribute Summary collapse

Attributes inherited from BasePolicy

#entity, #user

Instance Method Summary collapse

Methods inherited from BasePolicy

#available_actions_by_policy, call, define_policy_question, #registered_policy_questions, #registered_policy_questions?

Constructor Details

#initialize(user, sip, permission_query_service: nil) ⇒ SipPolicy



11
12
13
14
# File 'app/policies/sipity/policies/sip_policy.rb', line 11

def initialize(user, sip, permission_query_service: nil)
  super(user, sip)
  @permission_query_service = permission_query_service || default_permission_query_service
end

Instance Attribute Details

#original_entityObject (readonly, private)

Returns the value of attribute original_entity



15
16
17
# File 'app/policies/sipity/policies/sip_policy.rb', line 15

def original_entity
  @original_entity
end

#permission_query_serviceObject (readonly, private)

Returns the value of attribute permission_query_service



15
16
17
# File 'app/policies/sipity/policies/sip_policy.rb', line 15

def permission_query_service
  @permission_query_service
end

Instance Method Details

#default_permission_query_serviceObject (private)

TODO: Work with underlying Scoping query



45
46
47
48
49
50
# File 'app/policies/sipity/policies/sip_policy.rb', line 45

def default_permission_query_service
  lambda do |options|
    Models::Permission.
      where(actor: options.fetch(:user), entity: options.fetch(:entity), role: options.fetch(:roles)).any?
  end
end