ability.rb revision f4f335875509867dd238df7c92b0b8f4fe101705
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
432ee743a5f1c5688c73446b5977b06ed97fb67cJulian Kornberger # Comments
432ee743a5f1c5688c73446b5977b06ed97fb67cJulian Kornberger can [:create], Comment
8566aec18eff0f0d248d73d2f44f9df16cc41456Julian Kornberger can [:destroy], Comment do |subject|
8566aec18eff0f0d248d73d2f44f9df16cc41456Julian Kornberger subject.user == user || subject.commentable.permission?(:owner, user)
8566aec18eff0f0d248d73d2f44f9df16cc41456Julian Kornberger end
432ee743a5f1c5688c73446b5977b06ed97fb67cJulian Kornberger
f4f335875509867dd238df7c92b0b8f4fe101705Julian Kornberger can [:create, :destroy], Metadatum do |subject|
f4f335875509867dd238df7c92b0b8f4fe101705Julian Kornberger # TODO tests written?
f4f335875509867dd238df7c92b0b8f4fe101705Julian Kornberger subject.user == user || subject.metadatable.permission?(:editor, user)
f4f335875509867dd238df7c92b0b8f4fe101705Julian Kornberger end
c1c9b51cf3a275c9631b6de90e71b833bf97ded9Julian 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