Commit 7d3efec7d190948423d7e40a3f87e2d62b4ea808
Committed by
Dmitriy Zaporozhets
1 parent
695becc4
Exists in
master
and in
4 other branches
Add ability to teams
Showing
1 changed file
with
17 additions
and
0 deletions
Show diff stats
app/models/ability.rb
| @@ -8,6 +8,7 @@ class Ability | @@ -8,6 +8,7 @@ class Ability | ||
| 8 | when "Snippet" then snippet_abilities(object, subject) | 8 | when "Snippet" then snippet_abilities(object, subject) |
| 9 | when "MergeRequest" then merge_request_abilities(object, subject) | 9 | when "MergeRequest" then merge_request_abilities(object, subject) |
| 10 | when "Group", "Namespace" then group_abilities(object, subject) | 10 | when "Group", "Namespace" then group_abilities(object, subject) |
| 11 | + when "UserTeam" then user_team_abilities(object, subject) | ||
| 11 | else [] | 12 | else [] |
| 12 | end | 13 | end |
| 13 | end | 14 | end |
| @@ -110,6 +111,22 @@ class Ability | @@ -110,6 +111,22 @@ class Ability | ||
| 110 | rules.flatten | 111 | rules.flatten |
| 111 | end | 112 | end |
| 112 | 113 | ||
| 114 | + def user_team_abilities user, team | ||
| 115 | + rules = [] | ||
| 116 | + | ||
| 117 | + # Only group owner and administrators can manage group | ||
| 118 | + if team.owner == user || team.admin?(user) || user.admin? | ||
| 119 | + rules << [ :manage_user_team ] | ||
| 120 | + end | ||
| 121 | + | ||
| 122 | + if team.owner == user || user.admin? | ||
| 123 | + rules << [ :admin_user_team ] | ||
| 124 | + end | ||
| 125 | + | ||
| 126 | + rules.flatten | ||
| 127 | + end | ||
| 128 | + | ||
| 129 | + | ||
| 113 | [:issue, :note, :snippet, :merge_request].each do |name| | 130 | [:issue, :note, :snippet, :merge_request].each do |name| |
| 114 | define_method "#{name}_abilities" do |user, subject| | 131 | define_method "#{name}_abilities" do |user, subject| |
| 115 | if subject.author == user | 132 | if subject.author == user |