Class: SimpleTeams::Ability
- Inherits:
-
Object
- Object
- SimpleTeams::Ability
- Includes:
- CanCan::Ability
- Defined in:
- app/models/simple_teams/ability.rb
Instance Method Summary collapse
-
#initialize(user) ⇒ Ability
constructor
A new instance of Ability.
Constructor Details
#initialize(user) ⇒ Ability
Returns a new instance of Ability.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/simple_teams/ability.rb', line 5 def initialize(user) return unless user.present? can :create, Team # Team can :read, Team do |team| user.member_of_team?(team) end can [:update], Team do |team| %w"owner administrator".include? user.role_for_team(team) end can [:destroy], Team do |team| %w"owner".include? user.role_for_team(team) end # Team Memberships/Invitations can :read, [Membership, Invitation] do |object| user.member_of_team?(object.team) end can :manage, [Membership, Invitation] do |object| %w"owner administrator".include? user.role_for_team(object.team) end end |