Class: Sipity::Policies::SipPolicy::Scope

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

Overview

Responsible for building a scoped query to find a collection of Model::Sip objects for the given user.

Responsible for answering the following:

Given a user and an array of permitted roles, what are all the entities within the scope that I can “see”

See Also:

  • gem scopes](https://github.com/elabs/pundit#scopes) for more information regarding the Scope interface.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, scope = Models::Sip, permitted_roles: [Models::Permission::CREATING_USER]) ⇒ Scope


66
67
68
69
70
# File 'app/policies/sipity/policies/sip_policy.rb', line 66

def initialize(user, scope = Models::Sip, permitted_roles: [Models::Permission::CREATING_USER])
  @user = user
  @scope = scope
  @permitted_roles = permitted_roles
end

Instance Attribute Details

#permitted_rolesObject (readonly, private)

Returns the value of attribute permitted_roles


71
72
73
# File 'app/policies/sipity/policies/sip_policy.rb', line 71

def permitted_roles
  @permitted_roles
end

#scopeObject (readonly, private)

Returns the value of attribute scope


71
72
73
# File 'app/policies/sipity/policies/sip_policy.rb', line 71

def scope
  @scope
end

#userObject (readonly, private)

Returns the value of attribute user


71
72
73
# File 'app/policies/sipity/policies/sip_policy.rb', line 71

def user
  @user
end

Class Method Details

.resolve(user:, scope: Models::Sip, permitted_roles: [Models::Permission::CREATING_USER]) ⇒ Object


63
64
65
# File 'app/policies/sipity/policies/sip_policy.rb', line 63

def self.resolve(user:, scope: Models::Sip, permitted_roles: [Models::Permission::CREATING_USER])
  new(user, scope, permitted_roles: permitted_roles).resolve
end

Instance Method Details

#resolveObject


74
75
76
# File 'app/policies/sipity/policies/sip_policy.rb', line 74

def resolve
  Queries::PermissionQueries.scope_entities_for_user_and_roles(user: user, entity_type: scope, roles: permitted_roles)
end