Class: G5Updatable::SelectableClientPolicy::Scope

Inherits:
G5Authenticatable::BasePolicy::BaseScope show all
Defined in:
app/policies/g5_updatable/selectable_client_policy.rb

Instance Attribute Summary

Attributes inherited from G5Authenticatable::BasePolicy::BaseScope

#scope, #user

Instance Method Summary collapse

Methods inherited from G5Authenticatable::BasePolicy::BaseScope

#global_role?, #initialize

Constructor Details

This class inherits a constructor from G5Authenticatable::BasePolicy::BaseScope

Instance Method Details

#client_rolesObject



13
14
15
16
17
18
# File 'app/policies/g5_updatable/selectable_client_policy.rb', line 13

def client_roles
  G5Authenticatable::Role
    .joins('INNER JOIN g5_updatable_clients as c ON c.id = g5_authenticatable_roles.resource_id')
    .joins('INNER JOIN g5_authenticatable_users_roles as ur ON g5_authenticatable_roles.id = ur.role_id')
    .where('g5_authenticatable_roles.resource_type = ? and ur.user_id = ?', G5Updatable::Client.name, user.id)
end

#clients_from_client_and_location_rolesObject



20
21
22
23
24
# File 'app/policies/g5_updatable/selectable_client_policy.rb', line 20

def clients_from_client_and_location_roles
  return scope.all if has_global_role?
  client_ids = clients_from_location_roles.map(&:id) | client_roles.map(&:resource_id)
  G5Updatable::Client.where(id: client_ids)
end

#clients_from_location_rolesObject



26
27
28
29
30
31
32
33
34
# File 'app/policies/g5_updatable/selectable_client_policy.rb', line 26

def clients_from_location_roles
  G5Updatable::Client
    .joins('INNER JOIN g5_updatable_locations as l on l.client_uid=g5_updatable_clients.uid')
    .joins('INNER JOIN g5_authenticatable_roles as r on l.id=r.resource_id')
    .joins('INNER JOIN g5_authenticatable_users_roles as ur on r.id=ur.role_id')
    .where('r.resource_type = ? and ur.user_id = ?',
           G5Updatable::Location.name, user.id)
    .group('g5_updatable_clients.id')
end

#resolveObject



9
10
11
# File 'app/policies/g5_updatable/selectable_client_policy.rb', line 9

def resolve
  clients_from_client_and_location_roles
end