Class: WorkItems::Type
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- WorkItems::Type
- Includes:
- CacheMarkdownField, Gitlab::Utils::StrongMemoize
- Defined in:
- app/models/work_items/type.rb
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: 'work-item-issue', enum_value: 0, id: 1 }, incident: { name: TYPE_NAMES[:incident], icon_name: 'work-item-incident', enum_value: 1, id: 2 }, test_case: { name: TYPE_NAMES[:test_case], icon_name: 'work-item-test-case', enum_value: 2, id: 3 }, ## EE-only requirement: { name: TYPE_NAMES[:requirement], icon_name: 'work-item-requirement', enum_value: 3, id: 4 }, ## EE task: { name: TYPE_NAMES[:task], icon_name: 'work-item-task', enum_value: 4, id: 5 }, objective: { name: TYPE_NAMES[:objective], icon_name: 'work-item-objective', enum_value: 5, id: 6 }, ## EE-only key_result: { name: TYPE_NAMES[:key_result], icon_name: 'work-item-keyresult', enum_value: 6, id: 7 }, ## EE-only epic: { name: TYPE_NAMES[:epic], icon_name: 'work-item-epic', enum_value: 7, id: 8 }, ## EE-only ticket: { name: TYPE_NAMES[:ticket], icon_name: 'work-item-ticket', 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
Constants included from CacheMarkdownField
CacheMarkdownField::INVALIDATED_BY
Constants inherited from ApplicationRecord
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
Instance Attribute Summary
Attributes included from CacheMarkdownField
#skip_markdown_cache_validation
Class Method Summary collapse
Instance Method Summary collapse
- #allowed_child_types(authorize: false, resource_parent: nil) ⇒ Object
- #allowed_child_types_by_name ⇒ Object
- #allowed_parent_types(authorize: false, resource_parent: nil) ⇒ Object
- #allowed_parent_types_by_name ⇒ Object
-
#archived? ⇒ Boolean
Temporary method for adding configuration thought the API.
-
#can_promote_to_objective? ⇒ Boolean
Temporary method for adding configuration thought the API.
-
#configurable? ⇒ Boolean
Temporary method for adding configuration thought the API.
-
#creatable? ⇒ Boolean
Temporary method for adding configuration thought the API.
- #descendant_types ⇒ Object
-
#filterable? ⇒ Boolean
Temporary method for adding configuration thought the API.
-
#incident_management? ⇒ Boolean
Temporary method for adding configuration thought the API.
-
#only_for_group? ⇒ Boolean
Temporary method for adding configuration thought the API.
-
#service_desk? ⇒ Boolean
Temporary method for adding configuration thought the API.
-
#show_project_selector? ⇒ Boolean
Temporary method for adding configuration thought the API.
- #supported_conversion_types(resource_parent, user) ⇒ Object
- #supports_assignee?(resource_parent) ⇒ Boolean
-
#supports_move_action? ⇒ Boolean
Temporary method for adding configuration thought the API.
-
#supports_roadmap_view? ⇒ Boolean
Temporary method for adding configuration thought the API.
- #supports_time_tracking?(resource_parent) ⇒ Boolean
- #unavailable_widgets_on_conversion(target_type, resource_parent) ⇒ Object
-
#use_legacy_view? ⇒ Boolean
Temporary method for adding configuration thought the API.
-
#visible_in_settings? ⇒ Boolean
Temporary method for adding configuration thought the API.
- #widget_classes(resource_parent) ⇒ Object
-
#widgets(_resource_parent) ⇒ Object
resource_parent is used in EE.
Methods included from CacheMarkdownField
#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
Methods inherited from ApplicationRecord
===, 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!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from Organizations::Sharding
Methods included from ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
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) = <<~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, 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 (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::TypesFramework::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 (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::TypesFramework::SystemDefined::HierarchyRestriction .where(child_type_id: id) .map(&:parent_type_id) WorkItems::Type.where(id: parent_type_ids).order_by_name_asc end |
#archived? ⇒ Boolean
Temporary method for adding configuration thought the API
227 228 229 |
# File 'app/models/work_items/type.rb', line 227 def archived? nil end |
#can_promote_to_objective? ⇒ Boolean
Temporary method for adding configuration thought the API
187 188 189 |
# File 'app/models/work_items/type.rb', line 187 def can_promote_to_objective? nil end |
#configurable? ⇒ Boolean
Temporary method for adding configuration thought the API
212 213 214 |
# File 'app/models/work_items/type.rb', line 212 def configurable? nil end |
#creatable? ⇒ Boolean
Temporary method for adding configuration thought the API
217 218 219 |
# File 'app/models/work_items/type.rb', line 217 def creatable? nil 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 # We remove types that we've already seen to avoid circular dependencies 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.uniq end |
#filterable? ⇒ Boolean
Temporary method for adding configuration thought the API
232 233 234 |
# File 'app/models/work_items/type.rb', line 232 def filterable? nil end |
#incident_management? ⇒ Boolean
Temporary method for adding configuration thought the API
207 208 209 |
# File 'app/models/work_items/type.rb', line 207 def incident_management? nil end |
#only_for_group? ⇒ Boolean
Temporary method for adding configuration thought the API
237 238 239 |
# File 'app/models/work_items/type.rb', line 237 def only_for_group? nil end |
#service_desk? ⇒ Boolean
Temporary method for adding configuration thought the API
202 203 204 |
# File 'app/models/work_items/type.rb', line 202 def service_desk? nil end |
#show_project_selector? ⇒ Boolean
Temporary method for adding configuration thought the API
192 193 194 |
# File 'app/models/work_items/type.rb', line 192 def show_project_selector? nil 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) (resource_parent).include?(::WorkItems::Widgets::Assignees) end |
#supports_move_action? ⇒ Boolean
Temporary method for adding configuration thought the API
197 198 199 |
# File 'app/models/work_items/type.rb', line 197 def supports_move_action? nil end |
#supports_roadmap_view? ⇒ Boolean
Temporary method for adding configuration thought the API
177 178 179 |
# File 'app/models/work_items/type.rb', line 177 def supports_roadmap_view? nil 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) (resource_parent).include?(::WorkItems::Widgets::TimeTracking) end |
#unavailable_widgets_on_conversion(target_type, resource_parent) ⇒ Object
136 137 138 139 140 141 |
# File 'app/models/work_items/type.rb', line 136 def (target_type, resource_parent) = (resource_parent) = target_type.(resource_parent) = .map(&:widget_type).to_set .reject { || .include?(.) } end |
#use_legacy_view? ⇒ Boolean
Temporary method for adding configuration thought the API
182 183 184 |
# File 'app/models/work_items/type.rb', line 182 def use_legacy_view? nil end |
#visible_in_settings? ⇒ Boolean
Temporary method for adding configuration thought the API
222 223 224 |
# File 'app/models/work_items/type.rb', line 222 def visible_in_settings? nil end |
#widget_classes(resource_parent) ⇒ Object
104 105 106 |
# File 'app/models/work_items/type.rb', line 104 def (resource_parent) (resource_parent).map(&:widget_class) end |
#widgets(_resource_parent) ⇒ Object
resource_parent is used in EE
100 101 102 |
# File 'app/models/work_items/type.rb', line 100 def (_resource_parent) .filter(&:widget_class) end |