Sha256: 34df742f9e9082d5889c84b96963ffd1e0c42eeb4c823f24bce84761975ea21c

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# This class grant admin access only.
# This can be a good base class for your resource
# if you want to give access to admin only
class Underworld::AdminOnlyPolicy
  attr_reader :user, :record

  def initialize(user, record)
    @user = user
    @record = record
  end

  def index?
    return false if @user.nil?
    return true if @user.admin?
    false
  end

  def show?
    return false if @user.nil?
    return true if @user.admin?
    false
  end

  def create?
    return false if @user.nil?
    return true if @user.admin?
    false
  end

  def new?
    create?
  end

  def update?
    return false if @user.nil?
    return true if @user.admin?
    false
  end

  def edit?
    update?
  end

  def destroy?
    return false if @user.nil?
    return true if @user.admin?
    false
  end

  def scope
    Pundit.policy_scope!(@user, record.class)
  end

  class Scope
    attr_reader :user, :scope

    def initialize(user, scope)
      @@user = @user
      @scope = scope
    end

    def resolve
      scope
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
underworld-1.0.0 app/policies/underworld/admin_only_policy.rb