Class: WorkItems::DataSync::BaseCreateService

Inherits:
CreateService show all
Defined in:
app/services/work_items/data_sync/base_create_service.rb

Overview

This is a altered version of the WorkItem::CreateService. This overwrites the ‘initialize_callbacks!` and replaces the callbacks called by `WorkItem::CreateService` to setup data sync related callbacks which are used to copy data from the original work item to the target work item.

Constant Summary

Constants included from RateLimitedService

RateLimitedService::RateLimitedNotSetupError

Constants inherited from Issues::BaseService

Issues::BaseService::EpicAssignmentError, Issues::BaseService::NO_REBALANCING_NEEDED

Constants included from Gitlab::Utils::UsageData

Gitlab::Utils::UsageData::DISTRIBUTED_HLL_FALLBACK, Gitlab::Utils::UsageData::FALLBACK, Gitlab::Utils::UsageData::HISTOGRAM_FALLBACK, Gitlab::Utils::UsageData::MAX_BUCKET_SIZE

Instance Attribute Summary collapse

Attributes included from Issues::ResolveDiscussions

#discussion_to_resolve_id, #merge_request_to_resolve_discussions_object, #merge_request_to_resolve_discussions_of_iid

Attributes inherited from BaseContainerService

#container, #current_user, #group, #params, #project

Instance Method Summary collapse

Methods inherited from CreateService

#execute, #parent

Methods included from WidgetableService

#handle_quick_actions, #params_include_state_and_status_changes?

Methods inherited from Issues::CreateService

#after_create, #before_create, #execute, #external_author, #handle_assignee_changes, #handle_changes, #publish_event, #resolve_discussions_with_issue

Methods included from Services::ReturnServiceResponses

#error, #success

Methods included from Issues::ResolveDiscussions

#discussions_to_resolve, #filter_resolve_discussion_params, #merge_request_to_resolve_discussions_of

Methods included from RateLimitedService

#execute, #execute_without_rate_limiting

Methods inherited from Issues::BaseService

#available_callbacks, #close_service, #execute_hooks, #hook_data, #rebalance_if_needed, #reopen_service

Methods included from Gitlab::Utils::Override

#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!

Methods included from Issues::IssueTypeHelpers

#create_issue_type_allowed?

Methods included from IncidentManagement::UsageData

#track_incident_action

Methods included from Gitlab::Utils::UsageData

#add, #add_metric, #alt_usage_data, #average, #count, #distinct_count, #estimate_batch_distinct_count, #histogram, #maximum_id, #measure_duration, #metrics_collection_metadata, #minimum_id, #redis_usage_data, #sum, #track_usage_event, #with_finished_at, #with_metadata, #with_prometheus_client

Methods inherited from BaseContainerService

#group_container?, #namespace_container?, #project_container?, #project_group, #root_ancestor

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

#initialize(original_work_item:, operation:, **kwargs) ⇒ BaseCreateService

Returns a new instance of BaseCreateService.



11
12
13
14
15
16
# File 'app/services/work_items/data_sync/base_create_service.rb', line 11

def initialize(original_work_item:, operation:, **kwargs)
  super(**kwargs)

  @original_work_item = original_work_item
  @operation = operation
end

Instance Attribute Details

#operationObject (readonly)

Returns the value of attribute operation.



9
10
11
# File 'app/services/work_items/data_sync/base_create_service.rb', line 9

def operation
  @operation
end

#original_work_itemObject (readonly)

Returns the value of attribute original_work_item.



9
10
11
# File 'app/services/work_items/data_sync/base_create_service.rb', line 9

def original_work_item
  @original_work_item
end

#sync_data_paramsObject (readonly)

Returns the value of attribute sync_data_params.



9
10
11
# File 'app/services/work_items/data_sync/base_create_service.rb', line 9

def sync_data_params
  @sync_data_params
end

Instance Method Details

#initialize_callbacks!(work_item) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/services/work_items/data_sync/base_create_service.rb', line 18

def initialize_callbacks!(work_item)
  # reset system notes timestamp
  work_item.system_note_timestamp = nil
  @callbacks = original_work_item.widgets.filter_map do |widget|
    sync_data_callback_class = widget.class.sync_data_callback_class
    next if sync_data_callback_class.nil?

    callback_params = {}

    if sync_data_callback_class.const_defined?(:ALLOWED_PARAMS)
      callback_params.merge!(params.extract!(*sync_data_callback_class::ALLOWED_PARAMS))
    end

    sync_data_callback_class.new(
      work_item: original_work_item,
      target_work_item: work_item,
      current_user: current_user,
      params: callback_params.merge({ operation: operation })
    )
  end

  @callbacks += WorkItem.non_widgets.filter_map do |association_name|
    sync_callback_class = WorkItem.sync_callback_class(association_name)
    next if sync_callback_class.nil?

    sync_callback_class.new(
      work_item: original_work_item,
      target_work_item: work_item,
      current_user: current_user,
      params: { operation: operation }
    )
  end

  @callbacks
end