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/protected_branch.rb')
-rw-r--r--app/models/protected_branch.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb
index dfd5c315f6e..80967c1b072 100644
--- a/app/models/protected_branch.rb
+++ b/app/models/protected_branch.rb
@@ -4,6 +4,10 @@ class ProtectedBranch < ApplicationRecord
include ProtectedRef
include Gitlab::SQL::Pattern
+ belongs_to :group, foreign_key: :namespace_id, touch: true, inverse_of: :protected_branches
+
+ validate :validate_either_project_or_top_group
+
scope :requiring_code_owner_approval,
-> { where(code_owner_approval_required: true) }
@@ -99,6 +103,18 @@ class ProtectedBranch < ApplicationRecord
def default_branch?
name == project.default_branch
end
+
+ private
+
+ def validate_either_project_or_top_group
+ if !project && !group
+ errors.add(:base, _('must be associated with a Group or a Project'))
+ elsif project && group
+ errors.add(:base, _('cannot be associated with both a Group and a Project'))
+ elsif group && group.root_ancestor != group
+ errors.add(:base, _('cannot be associated with a subgroup'))
+ end
+ end
end
ProtectedBranch.prepend_mod_with('ProtectedBranch')