Skip to content

Instantly share code, notes, and snippets.

@brennovich
Created December 25, 2011 01:46
Show Gist options
  • Save brennovich/1518609 to your computer and use it in GitHub Desktop.
Save brennovich/1518609 to your computer and use it in GitHub Desktop.
Ability example.
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.type == 'Admin'
can :manage, [ThematicGroup, Coordinator]
can [:read, :edit, :update], MiniCourse
can :read, Participant
can :panel, Admin
elsif user.type == 'Coordinator'
can :read, ThematicGroup do |thematic_group|
user.thematic_group_ids.include? thematic_group.id
end
can [:read, :update], [Paper, Poster] do |submission|
user.thematic_group_ids.include? submission.thematic_group_id
end
can :panel, Coordinator
elsif user.type == 'Participant'
can :manage, [Paper, Poster, MiniCourse], :participant_id => user.id
can :panel, Participant
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment