Sha256: d72cde73adc5aaa0d68b9662a842dc2463614af4cf22a370bb056aad928a58ad

Contents?: true

Size: 709 Bytes

Versions: 7

Compression:

Stored size: 709 Bytes

Contents

# frozen_string_literal: true

class ApplicationPolicy
  attr_reader :current_user, :record

  def initialize(current_user, record)
    raise Pundit::NotAuthorizedError, 'must be logged in' unless current_user

    @current_user = current_user
    @record = record
  end

  def admin?
    current_user.admin? if current_user.present?
  end

  def staff?
    current_user.staff? if current_user.present?
  end

  # Used to verify if the persons role is set to either superuser or staff
  def staff_member?
    admin? || staff?
  end

  class Scope
    attr_reader :user, :scope

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

    def resolve
      scope.all
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kowl-0.0.7 lib/kowl/templates/app/policies/application_policy.rb
kowl-0.0.6 lib/kowl/templates/app/policies/application_policy.rb
kowl-0.0.5 lib/kowl/templates/app/policies/application_policy.rb
kowl-0.0.4 lib/kowl/templates/app/policies/application_policy.rb
kowl-0.0.3 lib/kowl/templates/app/policies/application_policy.rb
kowl-0.0.2 lib/kowl/templates/app/policies/application_policy.rb
kowl-0.0.1 lib/kowl/templates/app/policies/application_policy.rb