summaryrefslogtreecommitdiff
path: root/app/models/project.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-12-24 12:09:38 +0000
committerDouwe Maan <douwe@gitlab.com>2015-12-24 12:09:38 +0000
commit84e75ebd4cd463cf5e0dea9c46e7bcef50b98f50 (patch)
treed99d3a1ad52dcadd7b791b22bd56df6b2eee258c /app/models/project.rb
parent6b968a8fcdc1f67c4798d2f58004a5cf85e605b1 (diff)
parentc301ab0404229b0f3b0ff2cdd0482f1e0c0196ea (diff)
downloadgitlab-ce-84e75ebd4cd463cf5e0dea9c46e7bcef50b98f50.tar.gz
Merge branch 'fix/visibility-level-setting-in-forked-projects' into 'master'
Fix/visibility level setting in forked projects Fixes #3136 /cc @DouweM See merge request !1744
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb27
1 files changed, 24 insertions, 3 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index b28a7ca429c..75f85310d5f 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -64,6 +64,19 @@ class Project < ActiveRecord::Base
update_column(:last_activity_at, self.created_at)
end
+ # update visibility_levet of forks
+ after_update :update_forks_visibility_level
+ def update_forks_visibility_level
+ return unless visibility_level < visibility_level_was
+
+ forks.each do |forked_project|
+ if forked_project.visibility_level > visibility_level
+ forked_project.visibility_level = visibility_level
+ forked_project.save!
+ end
+ end
+ end
+
ActsAsTaggableOn.strict_case_match = true
acts_as_taggable_on :tags
@@ -100,9 +113,12 @@ class Project < ActiveRecord::Base
has_one :gitlab_issue_tracker_service, dependent: :destroy
has_one :external_wiki_service, dependent: :destroy
- has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
+ has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
+ has_one :forked_from_project, through: :forked_project_link
+
+ has_many :forked_project_links, foreign_key: "forked_from_project_id"
+ has_many :forks, through: :forked_project_links, source: :forked_to_project
- has_one :forked_from_project, through: :forked_project_link
# Merge Requests for target project should be removed with it
has_many :merge_requests, dependent: :destroy, foreign_key: 'target_project_id'
# Merge requests from source project should be kept when source project was removed
@@ -768,7 +784,7 @@ class Project < ActiveRecord::Base
end
def forks_count
- ForkedProjectLink.where(forked_from_project_id: self.id).count
+ forks.count
end
def find_label(name)
@@ -862,4 +878,9 @@ class Project < ActiveRecord::Base
def open_issues_count
issues.opened.count
end
+
+ def visibility_level_allowed?(level)
+ return true unless forked?
+ Gitlab::VisibilityLevel.allowed_fork_levels(forked_from_project.visibility_level).include?(level.to_i)
+ end
end