Class: WorkItems::Type
Constant Summary
collapse
- DEFAULT_TYPES_NOT_SEEDED =
Class.new(StandardError)
- TYPE_NAMES =
type name is used in restrictions DB seeder to assure restrictions for default types are pre-filled
{
issue: 'Issue',
incident: 'Incident',
test_case: 'Test Case',
requirement: 'Requirement',
task: 'Task',
objective: 'Objective',
key_result: 'Key Result',
epic: 'Epic',
ticket: 'Ticket'
}.freeze
- BASE_TYPES =
Base types need to exist on the DB on app startup This constant is used by the DB seeder TODO - where to add new icon names created?
{
issue: { name: TYPE_NAMES[:issue], icon_name: 'issue-type-issue', enum_value: 0, id: 1 },
incident: { name: TYPE_NAMES[:incident], icon_name: 'issue-type-incident', enum_value: 1, id: 2 },
test_case: { name: TYPE_NAMES[:test_case], icon_name: 'issue-type-test-case', enum_value: 2, id: 3 }, requirement: { name: TYPE_NAMES[:requirement], icon_name: 'issue-type-requirements', enum_value: 3, id: 4 }, task: { name: TYPE_NAMES[:task], icon_name: 'issue-type-task', enum_value: 4, id: 5 },
objective: { name: TYPE_NAMES[:objective], icon_name: 'issue-type-objective', enum_value: 5, id: 6 }, key_result: { name: TYPE_NAMES[:key_result], icon_name: 'issue-type-keyresult', enum_value: 6, id: 7 }, epic: { name: TYPE_NAMES[:epic], icon_name: 'issue-type-epic', enum_value: 7, id: 8 }, ticket: { name: TYPE_NAMES[:ticket], icon_name: 'issue-type-issue', enum_value: 8, id: 9 }
}.freeze
- CHANGEABLE_BASE_TYPES =
A list of types user can change between - both original and new type must be included in this list. This is needed for legacy issues where it’s possible to switch between issue and incident.
%w[issue incident test_case].freeze
- EE_BASE_TYPES =
%w[epic key_result objective requirement].freeze
CacheMarkdownField::INVALIDATED_BY
ApplicationRecord::MAX_PLUCK
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::MAX_RESET_PERIOD
Instance Attribute Summary
#skip_markdown_cache_validation
Class Method Summary
collapse
Instance Method Summary
collapse
#attribute_invalidated?, #banzai_render_context, #cached_html_for, #cached_html_up_to_date?, #can_cache_field?, #invalidated_markdown_cache?, #latest_cached_markdown_version, #mentionable_attributes_changed?, #mentioned_filtered_user_ids_for, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #store_mentions!, #store_mentions?, #store_mentions_after_commit?, #updated_cached_html_for
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, sharding_keys, #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
.default_by_type(type) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/models/work_items/type.rb', line 79
def self.default_by_type(type)
found_type = find_by(base_type: type)
return found_type if found_type || !WorkItems::Type.base_types.key?(type.to_s)
error_message = <<~STRING
Default work item types have not been created yet. Make sure the DB has been seeded successfully.
See related documentation in
https://docs.gitlab.com/omnibus/settings/database.html#seed-the-database-fresh-installs-only
If you have additional questions, you can ask in
https://gitlab.com/gitlab-org/gitlab/-/issues/423483
STRING
raise DEFAULT_TYPES_NOT_SEEDED, error_message
end
|
.default_issue_type ⇒ Object
95
96
97
|
# File 'app/models/work_items/type.rb', line 95
def self.default_issue_type
default_by_type(:issue)
end
|
Instance Method Details
#allowed_child_types(authorize: false, resource_parent: nil) ⇒ Object
143
144
145
146
147
148
149
|
# File 'app/models/work_items/type.rb', line 143
def allowed_child_types(authorize: false, resource_parent: nil)
types = allowed_child_types_by_name
return types unless authorize
authorized_types(types, resource_parent, :child)
end
|
#allowed_child_types_by_name ⇒ Object
116
117
118
119
120
121
122
|
# File 'app/models/work_items/type.rb', line 116
def allowed_child_types_by_name
child_type_ids = WorkItems::SystemDefined::HierarchyRestriction
.where(parent_type_id: id)
.map(&:child_type_id)
WorkItems::Type.where(id: child_type_ids).order_by_name_asc
end
|
#allowed_parent_types(authorize: false, resource_parent: nil) ⇒ Object
151
152
153
154
155
156
157
|
# File 'app/models/work_items/type.rb', line 151
def allowed_parent_types(authorize: false, resource_parent: nil)
types = allowed_parent_types_by_name
return types unless authorize
authorized_types(types, resource_parent, :parent)
end
|
#allowed_parent_types_by_name ⇒ Object
124
125
126
127
128
129
|
# File 'app/models/work_items/type.rb', line 124
def allowed_parent_types_by_name
parent_type_ids = WorkItems::SystemDefined::HierarchyRestriction
.where(child_type_id: id)
.map(&:parent_type_id)
WorkItems::Type.where(id: parent_type_ids).order_by_name_asc
end
|
#descendant_types ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'app/models/work_items/type.rb', line 159
def descendant_types
descendant_types = []
next_level_child_types = allowed_child_types
loop do
descendant_types += next_level_child_types
next_level_child_types = next_level_child_types.flat_map(&:allowed_child_types) - descendant_types
break if next_level_child_types.empty?
end
descendant_types
end
|
#supported_conversion_types(resource_parent, user) ⇒ Object
131
132
133
134
|
# File 'app/models/work_items/type.rb', line 131
def supported_conversion_types(resource_parent, user)
type_names = supported_conversion_base_types(resource_parent, user) - [base_type]
WorkItems::Type.by_type(type_names).order_by_name_asc
end
|
#supports_assignee?(resource_parent) ⇒ Boolean
108
109
110
|
# File 'app/models/work_items/type.rb', line 108
def supports_assignee?(resource_parent)
widget_classes(resource_parent).include?(::WorkItems::Widgets::Assignees)
end
|
#supports_time_tracking?(resource_parent) ⇒ Boolean
112
113
114
|
# File 'app/models/work_items/type.rb', line 112
def supports_time_tracking?(resource_parent)
widget_classes(resource_parent).include?(::WorkItems::Widgets::TimeTracking)
end
|
136
137
138
139
140
141
|
# File 'app/models/work_items/type.rb', line 136
def unavailable_widgets_on_conversion(target_type, resource_parent)
source_widgets = widgets(resource_parent)
target_widgets = target_type.widgets(resource_parent)
target_widget_types = target_widgets.map(&:widget_type).to_set
source_widgets.reject { |widget| target_widget_types.include?(widget.widget_type) }
end
|
104
105
106
|
# File 'app/models/work_items/type.rb', line 104
def widget_classes(resource_parent)
widgets(resource_parent).map(&:widget_class)
end
|
resource_parent is used in EE
100
101
102
|
# File 'app/models/work_items/type.rb', line 100
def widgets(_resource_parent)
enabled_widget_definitions.filter(&:widget_class)
end
|