Skip to content

Instantly share code, notes, and snippets.

@pedrosmmoreira
Created February 17, 2017 11:18
Show Gist options
  • Select an option

  • Save pedrosmmoreira/5d5e5dc5c3bd95ae8b1b64bafce0d921 to your computer and use it in GitHub Desktop.

Select an option

Save pedrosmmoreira/5d5e5dc5c3bd95ae8b1b64bafce0d921 to your computer and use it in GitHub Desktop.
class FooPolicy < ApplicationPolicy
#...
class Scope
#...
def resolve
if user.roles.include?("admin")
scope.not_cancelled
elsif user.roles.include?("official")
scope.not_draft
elsif user.roles.include?("provider")
scope.provided_by(user)
else
scope.none
end
end
end
def show?
(provider && !record.cancelled?) ||
(official || user_is_assigned_provider?(user))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment