Sha256: d7cfbb062eb2e2d193c6af707fe468b5c01d0b801ee00447a73c2f96cddf67e4

Contents?: true

Size: 868 Bytes

Versions: 8

Compression:

Stored size: 868 Bytes

Contents

module G5Updatable
  class ClientPolicy < G5Authenticatable::BasePolicy
    class Scope < G5Authenticatable::BasePolicy::BaseScope

      def resolve
        return scope.all if has_global_role?
        scope.where(id: client_roles.map(&:resource_id))
      end

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

      def has_global_role?
        G5Authenticatable::BasePolicy.new(user, G5Updatable::Client).has_global_role?
      end
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
g5_authenticatable-0.7.5 app/policies/g5_updatable/client_policy.rb
g5_authenticatable-0.7.5.beta app/policies/g5_updatable/client_policy.rb
g5_authenticatable-0.7.4 app/policies/g5_updatable/client_policy.rb
g5_authenticatable-0.7.4.beta.1 app/policies/g5_updatable/client_policy.rb
g5_authenticatable-0.7.3 app/policies/g5_updatable/client_policy.rb
g5_authenticatable-0.7.2 app/policies/g5_updatable/client_policy.rb
g5_authenticatable-0.7.1 app/policies/g5_updatable/client_policy.rb
g5_authenticatable-0.7.0 app/policies/g5_updatable/client_policy.rb