Sha256: a867b509bed3fd6892d99bb7d10dde0541a420eba5185a6e7f6a0d6e037b3619

Contents?: true

Size: 762 Bytes

Versions: 6

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

require 'proxes/policies/application_policy'

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

    def list?
      create?
    end

    def read?
      user && (record.id == user.id || user.super_admin?)
    end

    def update?
      read?
    end

    def delete?
      create?
    end

    def register?
      true
    end

    def permitted_attributes
      attribs = [:email, :name, :surname]
      attribs << :role_id if user.super_admin?
      attribs
    end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
proxes-0.7.0 lib/proxes/policies/user_policy.rb
proxes-0.6.1 lib/proxes/policies/user_policy.rb
proxes-0.6.0 lib/proxes/policies/user_policy.rb
proxes-0.5.2 lib/proxes/policies/user_policy.rb
proxes-0.5.1 lib/proxes/policies/user_policy.rb
proxes-0.5.0 lib/proxes/policies/user_policy.rb