Skip to content

Instantly share code, notes, and snippets.

@drusepth
Created August 16, 2017 23:27
Show Gist options
  • Save drusepth/6141899adde055d03405d649819096b6 to your computer and use it in GitHub Desktop.
Save drusepth/6141899adde055d03405d649819096b6 to your computer and use it in GitHub Desktop.
class ContentAuthorizer < ApplicationAuthorizer
def readable_by? user
[
PermissionService.user_owns_content?(user: user, content: resource),
PermissionService.content_is_public?(content: resource),
PermissionService.content_is_in_a_public_universe?(content: resource),
PermissionService.user_can_contribute_to_containing_universe?(user: user, content: resource)
].any?
end
def updatable_by? user
[
PermissionService.user_owns_containing_universe?(user: user, content: resource),
PermissionService.user_can_contribute_to_containing_universe?(user: user, content: resource),
[
PermissionService.content_has_no_containing_universe?(content: resource),
PermissionService.user_owns_content?(user: user, content: resource)
].all?
].any?
end
def deletable_by? user
[
PermissionService.user_owns_containing_universe?(user: user, content: resource),
[
PermissionService.content_has_no_containing_universe?(content: resource),
PermissionService.user_owns_content?(user: user, content: resource)
].all?
].any?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment