Sha256: 179bbdc3ec9a95436026bbf44680b05f5184a9d02d17ee9359195cb2b3516d7c

Contents?: true

Size: 683 Bytes

Versions: 3

Compression:

Stored size: 683 Bytes

Contents

# frozen_string_literal: true

require_relative 'application_policy'

module ProxES
  class TokenPolicy < ApplicationPolicy
    def create?
      user.super_admin?
    end

    def list?
      create?
    end

    def read?
      record.id == user.id || user.super_admin?
    end

    def update?
      read?
    end

    def delete?
      create?
    end

    def register?
      true
    end

    def permitted_attributes
      attribs = %i[email name surname]
      attribs << :role if user.super_admin?
      attribs
    end

    class Scope < ApplicationPolicy::Scope
      def resolve
        user && user.super_admin? ? scope : scope.where(id: -1)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
proxes-0.8.2 lib/proxes/policies/token_policy.rb
proxes-0.8.1 lib/proxes/policies/token_policy.rb
proxes-0.8.0 lib/proxes/policies/token_policy.rb