debian-mirror-gitlab/app/models/protected_branch.rb

51 lines
1.5 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
class ProtectedBranch < ApplicationRecord
2017-08-17 22:00:37 +05:30
include ProtectedRef
2014-09-02 18:07:02 +05:30
2019-12-04 20:38:33 +05:30
scope :requiring_code_owner_approval,
-> { where(code_owner_approval_required: true) }
2017-09-10 17:25:29 +05:30
protected_ref_access_levels :merge, :push
2016-09-13 17:45:13 +05:30
2018-05-09 12:01:36 +05:30
def self.protected_ref_accessible_to?(ref, user, project:, action:, protected_refs: nil)
2018-11-08 19:23:39 +05:30
# Maintainers, owners and admins are allowed to create the default branch
2018-05-09 12:01:36 +05:30
if default_branch_protected? && project.empty_repo?
return true if user.admin? || project.team.max_member_access(user.id) > Gitlab::Access::DEVELOPER
end
super
end
2017-08-17 22:00:37 +05:30
# Check if branch name is marked as protected in the system
def self.protected?(project, ref_name)
return true if project.empty_repo? && default_branch_protected?
2016-08-24 12:49:21 +05:30
2019-07-07 11:18:12 +05:30
self.matching(ref_name, protected_refs: protected_refs(project)).present?
end
2018-03-17 18:26:18 +05:30
2019-07-07 11:18:12 +05:30
def self.any_protected?(project, ref_names)
protected_refs(project).any? do |protected_ref|
ref_names.any? do |ref_name|
protected_ref.matches?(ref_name)
end
end
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
def self.default_branch_protected?
2018-03-17 18:26:18 +05:30
Gitlab::CurrentSettings.default_branch_protection == Gitlab::Access::PROTECTION_FULL ||
Gitlab::CurrentSettings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE
2016-08-24 12:49:21 +05:30
end
2019-07-07 11:18:12 +05:30
def self.protected_refs(project)
2019-12-26 22:10:19 +05:30
project.protected_branches
2019-07-07 11:18:12 +05:30
end
2019-12-21 20:55:43 +05:30
def self.branch_requires_code_owner_approval?(project, branch_name)
# NOOP
#
end
2014-09-02 18:07:02 +05:30
end
2019-12-04 20:38:33 +05:30
ProtectedBranch.prepend_if_ee('EE::ProtectedBranch')