Created
May 5, 2014 21:26
-
-
Save fresh5447/0521ed10d30fc3ce632f to your computer and use it in GitHub Desktop.
WikiPolicy
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.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