Commit e8e9e0f771c34cf45e9c42f69de4da6b747f07e0
1 parent
0273b79b
Exists in
master
and in
4 other branches
Use own abilities for namespace class
Showing
1 changed file
with
15 additions
and
1 deletions
Show diff stats
app/models/ability.rb
| @@ -10,7 +10,8 @@ class Ability | @@ -10,7 +10,8 @@ class Ability | ||
| 10 | when "ProjectSnippet" then project_snippet_abilities(user, subject) | 10 | when "ProjectSnippet" then project_snippet_abilities(user, subject) |
| 11 | when "PersonalSnippet" then personal_snippet_abilities(user, subject) | 11 | when "PersonalSnippet" then personal_snippet_abilities(user, subject) |
| 12 | when "MergeRequest" then merge_request_abilities(user, subject) | 12 | when "MergeRequest" then merge_request_abilities(user, subject) |
| 13 | - when "Group", "Namespace" then group_abilities(user, subject) | 13 | + when "Group" then group_abilities(user, subject) |
| 14 | + when "Namespace" then namespace_abilities(user, subject) | ||
| 14 | else [] | 15 | else [] |
| 15 | end.concat(global_abilities(user)) | 16 | end.concat(global_abilities(user)) |
| 16 | end | 17 | end |
| @@ -144,6 +145,19 @@ class Ability | @@ -144,6 +145,19 @@ class Ability | ||
| 144 | rules.flatten | 145 | rules.flatten |
| 145 | end | 146 | end |
| 146 | 147 | ||
| 148 | + def namespace_abilities user, namespace | ||
| 149 | + rules = [] | ||
| 150 | + | ||
| 151 | + # Only namespace owner and administrators can manage it | ||
| 152 | + if namespace.owner == user || user.admin? | ||
| 153 | + rules << [ | ||
| 154 | + :manage_namespace | ||
| 155 | + ] | ||
| 156 | + end | ||
| 157 | + | ||
| 158 | + rules.flatten | ||
| 159 | + end | ||
| 160 | + | ||
| 147 | [:issue, :note, :project_snippet, :personal_snippet, :merge_request].each do |name| | 161 | [:issue, :note, :project_snippet, :personal_snippet, :merge_request].each do |name| |
| 148 | define_method "#{name}_abilities" do |user, subject| | 162 | define_method "#{name}_abilities" do |user, subject| |
| 149 | if subject.author == user | 163 | if subject.author == user |