Sha256: 029281799d8f60a1616f6c7c8924b27cccaf6c6373430ea82014e810fb826cd0

Contents?: true

Size: 869 Bytes

Versions: 1

Compression:

Stored size: 869 Bytes

Contents

class ApplicationPolicy
  attr_reader :user, :record

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

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

  def index?
    admin? || editor? || contributor?
  end

  def show?
    index?
  end

  def create?
    admin?
  end

  def new?
    create?
  end

  def update?
    admin?
  end

  def edit?
    update?
  end

  def destroy?
    admin?
  end

  def view_hidden?
    admin? || editor? || contributor?
  end

  class Scope
    attr_reader :user, :scope

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

    def resolve
      scope
    end
  end

  private

    def admin?
      user.try(:admin?)
    end

    def editor?
      user.try(:in_group?, 'editor')
    end

    def contributor?
      user.try(:in_group?, 'contributor')
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forest_cms-0.98.1 app/policies/application_policy.rb