Skip to content

Instantly share code, notes, and snippets.

@evolve2k
Created February 17, 2011 02:11
Show Gist options
  • Select an option

  • Save evolve2k/830804 to your computer and use it in GitHub Desktop.

Select an option

Save evolve2k/830804 to your computer and use it in GitHub Desktop.
CanCan Abilities for Arbiters
#Abilities.rb:41 - Want some refactoring help
#
#Arbiters for a tournament can manage it
if user && !user.admin?
can [:read, :update, :destroy], Tournament, ['? in (select user_id from tournaments_users where tournament_id = tournaments.id) or tournaments.group_id in (select group_id from group_users where user_id = ? and role = \'Administrator\')', user.id, user.id] do |tournament|
tournament && (tournament.arbiters.include?(user) ||
(tournament.group && tournament.group.administrators.include?(user)))
end
can [:manage], [Division, Round, Pairing, Entry] do |x|
x && x.tournament && can?(:update, x.tournament)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment