Class: ProtectedBranch
Defined Under Namespace
Classes: CacheKey, MergeAccessLevel, PushAccessLevel
Constant Summary
Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_TERM
ApplicationRecord::MAX_PLUCK
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::MAX_RESET_PERIOD
Instance Attribute Summary
Attributes included from Importable
#importing, #user_contributions
Class Method Summary
collapse
Instance Method Summary
collapse
#present
split_query_to_search_terms
#commit
===, cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, nullable_column?, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#reset_on_union_error, #reset_on_unknown_attribute_error
#serializable_hash
Class Method Details
.allow_force_push?(project, ref_name) ⇒ Boolean
55
56
57
|
# File 'app/models/protected_branch.rb', line 55
def self.allow_force_push?(project, ref_name)
project.all_protected_branches.allowing_force_push.matching(ref_name).any?
end
|
.any_protected?(project, ref_names) ⇒ Boolean
59
60
61
62
63
64
65
|
# File 'app/models/protected_branch.rb', line 59
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
end
|
.branch_requires_code_owner_approval?(project, branch_name) ⇒ Boolean
72
73
74
|
# File 'app/models/protected_branch.rb', line 72
def self.branch_requires_code_owner_approval?(project, branch_name)
false
end
|
.by_name(query) ⇒ Object
76
77
78
79
80
|
# File 'app/models/protected_branch.rb', line 76
def self.by_name(query)
return none if query.blank?
where(fuzzy_arel_match(:name, query.downcase))
end
|
.downcase_humanized_name ⇒ Object
82
83
84
|
# File 'app/models/protected_branch.rb', line 82
def self.downcase_humanized_name
name.underscore.humanize.downcase
end
|
.get_ids_by_name(name) ⇒ Object
25
26
27
|
# File 'app/models/protected_branch.rb', line 25
def self.get_ids_by_name(name)
where(name: name).pluck(:id)
end
|
.protected?(project, ref_name) ⇒ Boolean
Check if branch name is marked as protected in the system
46
47
48
49
50
51
52
53
|
# File 'app/models/protected_branch.rb', line 46
def self.protected?(project, ref_name)
return true if project.empty_repo? && project.default_branch_protected?
return false if ref_name.blank?
ProtectedBranches::CacheService.new(project).fetch(ref_name) do self.matching(ref_name, protected_refs: protected_refs(project)).present?
end
end
|
.protected_ref_accessible_to?(ref, user, project:, action:, protected_refs: nil) ⇒ Boolean
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/models/protected_branch.rb', line 29
def self.protected_ref_accessible_to?(ref, user, project:, action:, protected_refs: nil)
if project.empty_repo?
member_access = project.team.max_member_access(user.id)
return true if user.admin? || user.can?(:admin_project, project)
if member_access == Gitlab::Access::DEVELOPER && project.initial_push_to_default_branch_allowed_for_developer?
return true
end
end
super
end
|
.protected_refs(project) ⇒ Object
67
68
69
|
# File 'app/models/protected_branch.rb', line 67
def self.protected_refs(project)
project.all_protected_branches
end
|
Instance Method Details
#default_branch? ⇒ Boolean
86
87
88
89
90
|
# File 'app/models/protected_branch.rb', line 86
def default_branch?
return false unless project.present?
name == project.default_branch
end
|
#entity ⇒ Object
100
101
102
|
# File 'app/models/protected_branch.rb', line 100
def entity
group || project
end
|
#group_level? ⇒ Boolean
92
93
94
|
# File 'app/models/protected_branch.rb', line 92
def group_level?
entity.is_a?(Group)
end
|
#project_level? ⇒ Boolean
96
97
98
|
# File 'app/models/protected_branch.rb', line 96
def project_level?
entity.is_a?(Project)
end
|