ability.rb revision be6eb5d7ea1888f2f835fe0fff358f72572afeb4
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornbergerclass Ability
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger include CanCan::Ability
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger def initialize(user)
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger # Define abilities for the passed in user here.
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger user ||= User.new # guest user (not logged in)
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger if user.admin?
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger can { true }
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger elsif user.id
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger # Ontologies
be6eb5d7ea1888f2f835fe0fff358f72572afeb4henning mueller can [:edit, :update], Ontology do |subject|
be6eb5d7ea1888f2f835fe0fff358f72572afeb4henning mueller subject.permission?(:editor, user)
be6eb5d7ea1888f2f835fe0fff358f72572afeb4henning mueller end
be6eb5d7ea1888f2f835fe0fff358f72572afeb4henning mueller can [:destroy, :permissions], Ontology do |subject|
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger subject.permission?(:owner, user)
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger end
c089c2e01fd049de4c25af718af1a26b8846c890Julian Kornberger can [:new, :create], Ontology
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger # Team permissions
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger can [:create, :show, :index], Team
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger can [:edit, :update, :destroy], Team do |subject|
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger subject.admin?(user)
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger end
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger end
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger # See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornberger end
7b025f9d9726413eb3f50ca2b39826e7eed816fbJulian Kornbergerend