summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-05-14 08:43:08 +0000
committerGitLab Release Tools Bot <robert+release-tools@gitlab.com>2019-05-14 16:31:22 +0000
commit959962db5634ad5e8703b21031bd08a4c5ab902a (patch)
tree2b149cb58320ab686162e80e71d966507e8738b6
parentacf15521f7abb5318281e011f9a186893e1e7655 (diff)
downloadgitlab-ce-11-11-stable-prepare-rc3.tar.gz
Merge branch 'fix-project-visibility-level-validation' into 'master'11-11-stable-prepare-rc3
Fix project visibility level validation Closes #59379 See merge request gitlab-org/gitlab-ce!28305 (cherry picked from commit 99637084b22abdf7b1f6d46daad80faf8181f3cd) b5540112 Fix project visibility level validation
-rw-r--r--app/models/project.rb8
-rw-r--r--changelogs/unreleased/fix-project-visibility-level-validation.yml5
-rw-r--r--spec/models/project_spec.rb7
3 files changed, 18 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 61d245478ca..68b5c299df4 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -337,8 +337,8 @@ class Project < ApplicationRecord
validates :star_count, numericality: { greater_than_or_equal_to: 0 }
validate :check_personal_projects_limit, on: :create
validate :check_repository_path_availability, on: :update, if: ->(project) { project.renamed? }
- validate :visibility_level_allowed_by_group, if: -> { changes.has_key?(:visibility_level) }
- validate :visibility_level_allowed_as_fork, if: -> { changes.has_key?(:visibility_level) }
+ validate :visibility_level_allowed_by_group, if: :should_validate_visibility_level?
+ validate :visibility_level_allowed_as_fork, if: :should_validate_visibility_level?
validate :check_wiki_path_conflict
validate :validate_pages_https_only, if: -> { changes.has_key?(:pages_https_only) }
validates :repository_storage,
@@ -892,6 +892,10 @@ class Project < ApplicationRecord
self.errors.add(:limit_reached, error % { limit: limit })
end
+ def should_validate_visibility_level?
+ new_record? || changes.has_key?(:visibility_level)
+ end
+
def visibility_level_allowed_by_group
return if visibility_level_allowed_by_group?
diff --git a/changelogs/unreleased/fix-project-visibility-level-validation.yml b/changelogs/unreleased/fix-project-visibility-level-validation.yml
new file mode 100644
index 00000000000..9581a475842
--- /dev/null
+++ b/changelogs/unreleased/fix-project-visibility-level-validation.yml
@@ -0,0 +1,5 @@
+---
+title: Fix project visibility level validation
+merge_request: 28305
+author: Peter Marko
+type: fixed
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 2a17bd6002e..425096d7e80 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -214,6 +214,13 @@ describe Project do
expect(project2).not_to be_valid
end
+ it 'validates the visibility' do
+ expect_any_instance_of(described_class).to receive(:visibility_level_allowed_as_fork).and_call_original
+ expect_any_instance_of(described_class).to receive(:visibility_level_allowed_by_group).and_call_original
+
+ create(:project)
+ end
+
describe 'wiki path conflict' do
context "when the new path has been used by the wiki of other Project" do
it 'has an error on the name attribute' do