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
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/namespace_setting.rb')
-rw-r--r--app/models/namespace_setting.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/models/namespace_setting.rb b/app/models/namespace_setting.rb
index e7f6db38047..5b114bb42aa 100644
--- a/app/models/namespace_setting.rb
+++ b/app/models/namespace_setting.rb
@@ -12,8 +12,12 @@ class NamespaceSetting < ApplicationRecord
enum jobs_to_be_done: { basics: 0, move_repository: 1, code_storage: 2, exploring: 3, ci: 4, other: 5 }, _suffix: true
enum enabled_git_access_protocol: { all: 0, ssh: 1, http: 2 }, _suffix: true
+ attribute :default_branch_protection_defaults, default: -> { {} }
+
validates :enabled_git_access_protocol, inclusion: { in: enabled_git_access_protocols.keys }
validates :code_suggestions, allow_nil: false, inclusion: { in: [true, false] }
+ validates :default_branch_protection_defaults, json_schema: { filename: 'default_branch_protection_defaults' }
+ validates :default_branch_protection_defaults, bytesize: { maximum: -> { DEFAULT_BRANCH_PROTECTIONS_DEFAULT_MAX_SIZE } }
validate :allow_mfa_for_group
validate :allow_resource_access_token_creation_for_group
@@ -22,6 +26,8 @@ class NamespaceSetting < ApplicationRecord
before_validation :normalize_default_branch_name
+ after_create :set_code_suggestions_default
+
chronic_duration_attr :runner_token_expiration_interval_human_readable, :runner_token_expiration_interval
chronic_duration_attr :subgroup_runner_token_expiration_interval_human_readable, :subgroup_runner_token_expiration_interval
chronic_duration_attr :project_runner_token_expiration_interval_human_readable, :project_runner_token_expiration_interval
@@ -41,6 +47,9 @@ class NamespaceSetting < ApplicationRecord
project_runner_token_expiration_interval
].freeze
+ # matches the size set in the database constraint
+ DEFAULT_BRANCH_PROTECTIONS_DEFAULT_MAX_SIZE = 1.kilobyte
+
self.primary_key = :namespace_id
def self.allowed_namespace_settings_params
@@ -87,6 +96,14 @@ class NamespaceSetting < ApplicationRecord
self.default_branch_name = default_branch_name.presence
end
+ def set_code_suggestions_default
+ # users should have code suggestions disabled by default
+ return if namespace&.user_namespace?
+
+ # groups should have code suggestions enabled by default
+ update_column(:code_suggestions, true)
+ end
+
def allow_mfa_for_group
if namespace&.subgroup? && allow_mfa_for_subgroups == false
errors.add(:allow_mfa_for_subgroups, _('is not allowed since the group is not top-level group.'))