Skip to content

Instantly share code, notes, and snippets.

@imoss
Created May 1, 2013 18:44
Show Gist options
  • Save imoss/5497335 to your computer and use it in GitHub Desktop.
Save imoss/5497335 to your computer and use it in GitHub Desktop.
class Gatekeeper
attr_accessor :user, :contexts
def initialize(user, contexts)
self.user = user
self.contexts = Array.wrap(contexts)
end
def self.access?(user: user, contexts: contexts)
new(user, contexts).access?
end
def access?
group_permission || user_permission
end
def group_permission
GroupPermission.where(context_id: contexts, group_id: user.groups)
end
def user_permission
UserPermission.where(context_id: contexts, user_id: user.id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment