Created
December 25, 2011 01:46
-
-
Save brennovich/1518609 to your computer and use it in GitHub Desktop.
Ability example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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