2012-02-15 15:02:33 -05:00
|
|
|
class ProtectedBranch < ActiveRecord::Base
|
2013-03-21 15:01:14 -04:00
|
|
|
include Gitlab::ShellAdapter
|
2017-04-03 10:17:24 -04:00
|
|
|
include ProtectedRef
|
2012-02-15 15:02:33 -05:00
|
|
|
|
2016-08-16 01:09:13 -04:00
|
|
|
has_many :merge_access_levels, dependent: :destroy
|
|
|
|
has_many :push_access_levels, dependent: :destroy
|
2016-07-05 03:40:42 -04:00
|
|
|
|
2017-02-21 19:40:04 -05:00
|
|
|
validates :merge_access_levels, length: { is: 1, message: "are restricted to a single instance per protected branch." }
|
|
|
|
validates :push_access_levels, length: { is: 1, message: "are restricted to a single instance per protected branch." }
|
2016-08-16 01:09:13 -04:00
|
|
|
|
|
|
|
accepts_nested_attributes_for :push_access_levels
|
|
|
|
accepts_nested_attributes_for :merge_access_levels
|
2017-04-03 13:59:58 -04:00
|
|
|
|
|
|
|
# Check if branch name is marked as protected in the system
|
|
|
|
def self.protected?(project, ref_name)
|
2017-04-03 14:28:54 -04:00
|
|
|
return true if project.empty_repo? && default_branch_protected?
|
2017-04-03 13:59:58 -04:00
|
|
|
|
2017-04-03 14:47:08 -04:00
|
|
|
self.matching(ref_name, protected_refs: project.protected_branches).present?
|
2017-04-03 13:59:58 -04:00
|
|
|
end
|
2017-04-03 14:28:54 -04:00
|
|
|
|
|
|
|
def self.default_branch_protected?
|
|
|
|
current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_FULL ||
|
|
|
|
current_application_settings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE
|
|
|
|
end
|
2012-02-15 15:02:33 -05:00
|
|
|
end
|