Skip to content

Instantly share code, notes, and snippets.

@manveru manveru/ability.cr Secret
Created Dec 1, 2019

Embed
What would you like to do?
module Ability
abstract def current_user : User
def can_edit?(other : User)
other.id == user.id || user.admin?
end
def can_delete?(other : User)
other.id == user.id || user.admin?
end
def can_edit?(organizer : Organizer)
organizer.editor_id == user.id || user.admin?
end
def can_edit?(organizer : Organizer.class)
user.admin? || user.editor?
end
def can_delete?(organizer : Organizer)
organizer.editor_id == user.id || user.admin?
end
def can_delete?(organizer : Organizer.class)
user.admin? || user.editor?
end
def can_edit?(event : Event)
event.editor_id == user.id || user.admin?
end
def can_edit?(e : Event.class)
user.admin?
end
def can_delete?(event : Event)
event.editor_id == user.id || user.admin?
end
def can_delete?(e : Event.class)
user.admin?
end
def user : User
current_user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.