-
-
Save xander-miller/4d5817b13e55d04ef2cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.private? && (wiki.user == user || wiki.collaborators.map{|collab| collab.user}.include?(user)) | |
else | |
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