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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-10 15:11:00 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-10 15:11:00 +0300
commit63c306d96043ff012510358037c19053a2102e8a (patch)
treebcb2874d81dc9b3748b37d250a83d9a91f8b38b0 /app/models/namespace_setting.rb
parent5adf6557e251c047ed68bac28cfecf9491ee6b41 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/namespace_setting.rb')
-rw-r--r--app/models/namespace_setting.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/namespace_setting.rb b/app/models/namespace_setting.rb
index a04cf00b5ea..4a39bfebda0 100644
--- a/app/models/namespace_setting.rb
+++ b/app/models/namespace_setting.rb
@@ -11,6 +11,9 @@ class NamespaceSetting < ApplicationRecord
validate :allow_mfa_for_group
validate :allow_resource_access_token_creation_for_group
+ before_save :set_prevent_sharing_groups_outside_hierarchy, if: -> { user_cap_enabled? }
+ after_save :disable_project_sharing!, if: -> { user_cap_enabled? }
+
before_validation :normalize_default_branch_name
NAMESPACE_SETTINGS_PARAMS = [:default_branch_name, :delayed_project_removal,
@@ -19,6 +22,12 @@ class NamespaceSetting < ApplicationRecord
self.primary_key = :namespace_id
+ def prevent_sharing_groups_outside_hierarchy
+ return super if namespace.root?
+
+ namespace.root_ancestor.prevent_sharing_groups_outside_hierarchy
+ end
+
private
def normalize_default_branch_name
@@ -48,6 +57,18 @@ class NamespaceSetting < ApplicationRecord
errors.add(:resource_access_token_creation_allowed, _('is not allowed since the group is not top-level group.'))
end
end
+
+ def set_prevent_sharing_groups_outside_hierarchy
+ self.prevent_sharing_groups_outside_hierarchy = true
+ end
+
+ def disable_project_sharing!
+ namespace.update_attribute(:share_with_group_lock, true)
+ end
+
+ def user_cap_enabled?
+ new_user_signups_cap.present? && namespace.root?
+ end
end
NamespaceSetting.prepend_mod_with('NamespaceSetting')