Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2019-06-17 13:21:35 +0300
committerRémy Coutable <remy@rymai.me>2019-06-17 13:21:35 +0300
commitb37ca62686f10dd3c2107ce34c5e1ed800706c67 (patch)
treed3fd9f3c5c16f0094b646bce1ff5e3be451f97f3 /app
parentc6cf52915b076c1c12bfe3ae3628145bebd8f1a3 (diff)
parentdcba5279b6e4bda905f5fa37a557b94f1fd42ba9 (diff)
Merge branch 'sh-fix-issue-63158' into 'master'
Fix inability to set visibility_level on project via API Closes #63158 See merge request gitlab-org/gitlab-ce!29578
Diffstat (limited to 'app')
-rw-r--r--app/models/project.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 9d17d68eee2..fb06af8e97e 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -72,7 +72,6 @@ class Project < ApplicationRecord
delegate :no_import?, to: :import_state, allow_nil: true
default_value_for :archived, false
- default_value_for(:visibility_level) { Gitlab::CurrentSettings.default_project_visibility }
default_value_for :resolve_outdated_diff_discussions, false
default_value_for :container_registry_enabled, gitlab_config_features.container_registry
default_value_for(:repository_storage) { Gitlab::CurrentSettings.pick_repository_storage }
@@ -613,6 +612,23 @@ class Project < ApplicationRecord
end
end
+ def initialize(attributes = {})
+ # We can't use default_value_for because the database has a default
+ # value of 0 for visibility_level. If someone attempts to create a
+ # private project, default_value_for will assume that the
+ # visibility_level hasn't changed and will use the application
+ # setting default, which could be internal or public. For projects
+ # inside a private group, those levels are invalid.
+ #
+ # To fix the problem, we assign the actual default in the application if
+ # no explicit visibility has been initialized.
+ unless visibility_attribute_present?(attributes)
+ attributes[:visibility_level] = Gitlab::CurrentSettings.default_project_visibility
+ end
+
+ super
+ end
+
def all_pipelines
if builds_enabled?
super