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,6 +188,13 @@ class Ability | ||
188 | rules << :read_group | 188 | rules << :read_group |
189 | end | 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 | # Only group owner and administrators can manage group | 198 | # Only group owner and administrators can manage group |
192 | if group.has_owner?(user) || user.admin? | 199 | if group.has_owner?(user) || user.admin? |
193 | rules += [ | 200 | rules += [ |
@@ -205,6 +212,7 @@ class Ability | @@ -205,6 +212,7 @@ class Ability | ||
205 | # Only namespace owner and administrators can manage it | 212 | # Only namespace owner and administrators can manage it |
206 | if namespace.owner == user || user.admin? | 213 | if namespace.owner == user || user.admin? |
207 | rules += [ | 214 | rules += [ |
215 | + :create_projects, | ||
208 | :manage_namespace | 216 | :manage_namespace |
209 | ] | 217 | ] |
210 | end | 218 | end |
app/models/group.rb
@@ -26,7 +26,7 @@ class Group < Namespace | @@ -26,7 +26,7 @@ class Group < Namespace | ||
26 | validates :avatar, file_size: { maximum: 100.kilobytes.to_i } | 26 | validates :avatar, file_size: { maximum: 100.kilobytes.to_i } |
27 | 27 | ||
28 | mount_uploader :avatar, AttachmentUploader | 28 | mount_uploader :avatar, AttachmentUploader |
29 | - | 29 | + |
30 | def self.accessible_to(user) | 30 | def self.accessible_to(user) |
31 | accessible_ids = Project.accessible_to(user).pluck(:namespace_id) | 31 | accessible_ids = Project.accessible_to(user).pluck(:namespace_id) |
32 | accessible_ids += user.groups.pluck(:id) if user | 32 | accessible_ids += user.groups.pluck(:id) if user |
@@ -60,6 +60,10 @@ class Group < Namespace | @@ -60,6 +60,10 @@ class Group < Namespace | ||
60 | owners.include?(user) | 60 | owners.include?(user) |
61 | end | 61 | end |
62 | 62 | ||
63 | + def has_master?(user) | ||
64 | + members.masters.where(user_id: user).any? | ||
65 | + end | ||
66 | + | ||
63 | def last_owner?(user) | 67 | def last_owner?(user) |
64 | has_owner?(user) && owners.size == 1 | 68 | has_owner?(user) && owners.size == 1 |
65 | end | 69 | end |
app/models/project.rb
@@ -387,10 +387,6 @@ class Project < ActiveRecord::Base | @@ -387,10 +387,6 @@ class Project < ActiveRecord::Base | ||
387 | end | 387 | end |
388 | end | 388 | end |
389 | 389 | ||
390 | - def transfer(new_namespace) | ||
391 | - ProjectTransferService.new.transfer(self, new_namespace) | ||
392 | - end | ||
393 | - | ||
394 | def execute_hooks(data, hooks_scope = :push_hooks) | 390 | def execute_hooks(data, hooks_scope = :push_hooks) |
395 | hooks.send(hooks_scope).each do |hook| | 391 | hooks.send(hooks_scope).each do |hook| |
396 | hook.async_execute(data) | 392 | hook.async_execute(data) |
app/models/user.rb
@@ -90,6 +90,8 @@ class User < ActiveRecord::Base | @@ -90,6 +90,8 @@ class User < ActiveRecord::Base | ||
90 | has_many :users_groups, dependent: :destroy | 90 | has_many :users_groups, dependent: :destroy |
91 | has_many :groups, through: :users_groups | 91 | has_many :groups, through: :users_groups |
92 | has_many :owned_groups, -> { where users_groups: { group_access: UsersGroup::OWNER } }, through: :users_groups, source: :group | 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 | # Projects | 95 | # Projects |
94 | has_many :groups_projects, through: :groups, source: :projects | 96 | has_many :groups_projects, through: :groups, source: :projects |
95 | has_many :personal_projects, through: :namespace, source: :projects | 97 | has_many :personal_projects, through: :namespace, source: :projects |