diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /app/models/protected_branch.rb | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) | |
download | gitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'app/models/protected_branch.rb')
-rw-r--r-- | app/models/protected_branch.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb index ad418a47476..cbbdd091feb 100644 --- a/app/models/protected_branch.rb +++ b/app/models/protected_branch.rb @@ -7,6 +7,9 @@ class ProtectedBranch < ApplicationRecord scope :requiring_code_owner_approval, -> { where(code_owner_approval_required: true) } + scope :allowing_force_push, + -> { where(allow_force_push: true) } + protected_ref_access_levels :merge, :push def self.protected_ref_accessible_to?(ref, user, project:, action:, protected_refs: nil) @@ -26,6 +29,12 @@ class ProtectedBranch < ApplicationRecord self.matching(ref_name, protected_refs: protected_refs(project)).present? end + def self.allow_force_push?(project, ref_name) + return false unless ::Feature.enabled?(:allow_force_push_to_protected_branches, project) + + project.protected_branches.allowing_force_push.matching(ref_name).any? + end + def self.any_protected?(project, ref_names) protected_refs(project).any? do |protected_ref| ref_names.any? do |ref_name| |