Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WikiPolicy
class WikiPolicy < ApplicationPolicy
class Scope < Struct.new(:user, :scope)
    def resolve
      if user.admin?
        scope.all
      else
        scope.where(user: user)
      end
    end
  end
def index?
    if user.role?(:admin)
        true
    elsif user.role?(:premium)
        wiki.user == user || wiki.collaborators.map{|collab| collab.user}.include?(user) || !wiki.private?
        true
    else
       :private => false
    end
  end
  
  def update?
    index?
  end
  def edit?
    index?
  end
  def create?
    user.present?
  end
  def show?
    wiki.private? ? update? : true
  end
  def destroy?
    update?
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment