Commit aea79b80351109506bd089694df6f22785456f68
1 parent
aca6be50
Exists in
spb-stable
and in
2 other branches
Add ability rule for creating project in namespace
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
4 changed files
with
15 additions
and
5 deletions
Show diff stats
app/models/ability.rb
... | ... | @@ -188,6 +188,13 @@ class Ability |
188 | 188 | rules << :read_group |
189 | 189 | end |
190 | 190 | |
191 | + # Only group masters and group owners can create new projects in group | |
192 | + if group.has_master?(user) || group.has_owner?(user) || user.admin? | |
193 | + rules += [ | |
194 | + :create_projects, | |
195 | + ] | |
196 | + end | |
197 | + | |
191 | 198 | # Only group owner and administrators can manage group |
192 | 199 | if group.has_owner?(user) || user.admin? |
193 | 200 | rules += [ |
... | ... | @@ -205,6 +212,7 @@ class Ability |
205 | 212 | # Only namespace owner and administrators can manage it |
206 | 213 | if namespace.owner == user || user.admin? |
207 | 214 | rules += [ |
215 | + :create_projects, | |
208 | 216 | :manage_namespace |
209 | 217 | ] |
210 | 218 | end | ... | ... |
app/models/group.rb
... | ... | @@ -26,7 +26,7 @@ class Group < Namespace |
26 | 26 | validates :avatar, file_size: { maximum: 100.kilobytes.to_i } |
27 | 27 | |
28 | 28 | mount_uploader :avatar, AttachmentUploader |
29 | - | |
29 | + | |
30 | 30 | def self.accessible_to(user) |
31 | 31 | accessible_ids = Project.accessible_to(user).pluck(:namespace_id) |
32 | 32 | accessible_ids += user.groups.pluck(:id) if user |
... | ... | @@ -60,6 +60,10 @@ class Group < Namespace |
60 | 60 | owners.include?(user) |
61 | 61 | end |
62 | 62 | |
63 | + def has_master?(user) | |
64 | + members.masters.where(user_id: user).any? | |
65 | + end | |
66 | + | |
63 | 67 | def last_owner?(user) |
64 | 68 | has_owner?(user) && owners.size == 1 |
65 | 69 | end | ... | ... |
app/models/project.rb
... | ... | @@ -387,10 +387,6 @@ class Project < ActiveRecord::Base |
387 | 387 | end |
388 | 388 | end |
389 | 389 | |
390 | - def transfer(new_namespace) | |
391 | - ProjectTransferService.new.transfer(self, new_namespace) | |
392 | - end | |
393 | - | |
394 | 390 | def execute_hooks(data, hooks_scope = :push_hooks) |
395 | 391 | hooks.send(hooks_scope).each do |hook| |
396 | 392 | hook.async_execute(data) | ... | ... |
app/models/user.rb
... | ... | @@ -90,6 +90,8 @@ class User < ActiveRecord::Base |
90 | 90 | has_many :users_groups, dependent: :destroy |
91 | 91 | has_many :groups, through: :users_groups |
92 | 92 | has_many :owned_groups, -> { where users_groups: { group_access: UsersGroup::OWNER } }, through: :users_groups, source: :group |
93 | + has_many :masters_groups, -> { where users_groups: { group_access: UsersGroup::MASTER } }, through: :users_groups, source: :group | |
94 | + | |
93 | 95 | # Projects |
94 | 96 | has_many :groups_projects, through: :groups, source: :projects |
95 | 97 | has_many :personal_projects, through: :namespace, source: :projects | ... | ... |