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>2023-01-18 22:00:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 22:00:14 +0300
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /app/models/users/namespace_commit_email.rb
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'app/models/users/namespace_commit_email.rb')
-rw-r--r--app/models/users/namespace_commit_email.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/app/models/users/namespace_commit_email.rb b/app/models/users/namespace_commit_email.rb
index 4ec02f12717..883b17187ca 100644
--- a/app/models/users/namespace_commit_email.rb
+++ b/app/models/users/namespace_commit_email.rb
@@ -9,6 +9,22 @@ module Users
validates :user, presence: true
validates :namespace, presence: true
validates :email, presence: true
- validates :user_id, uniqueness: { scope: [:namespace_id] }
+ validates :user, uniqueness: { scope: :namespace_id }
+ validate :validate_root_group
+
+ def self.delete_for_namespace(namespace)
+ where(namespace: namespace).delete_all
+ end
+
+ private
+
+ def validate_root_group
+ # Due to the way Rails validations are invoked all at once,
+ # namespace sometimes won't exist when this is ran even though we have a validation for presence first.
+ return unless namespace&.group_namespace?
+ return if namespace.root?
+
+ errors.add(:namespace, _('must be a root group.'))
+ end
end
end