summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-02-27 16:38:45 -0600
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2017-02-28 15:11:21 +0200
commit68faad16bd4bf81ccd1e279bc487fd02818b05d6 (patch)
treeddf84393180e9c62b6c7a8cb2d0a5d4399b223f3 /app
parent71fbbc9da428268411c5a3cef319f7537b63d199 (diff)
downloadgitlab-ce-68faad16bd4bf81ccd1e279bc487fd02818b05d6.tar.gz
Don't allow a project to be shared with an ancestor of the group it is in
Diffstat (limited to 'app')
-rw-r--r--app/models/project_group_link.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/app/models/project_group_link.rb b/app/models/project_group_link.rb
index 5cb6b0c527d..ac1e9ab2b0b 100644
--- a/app/models/project_group_link.rb
+++ b/app/models/project_group_link.rb
@@ -33,8 +33,15 @@ class ProjectGroupLink < ActiveRecord::Base
private
def different_group
- if self.group && self.project && self.project.group == self.group
- errors.add(:base, "Project cannot be shared with the project it is in.")
+ return unless self.group && self.project
+
+ project_group = self.project.group
+ return unless project_group
+
+ group_ids = project_group.ancestors.map(&:id).push(project_group.id)
+
+ if group_ids.include?(self.group.id)
+ errors.add(:base, "Project cannot be shared with the group it is in or one of its ancestors.")
end
end