Class: WorkItems::DataSync::Handlers::CopyDataHandler

Inherits:
Object
  • Object
show all
Defined in:
app/services/work_items/data_sync/handlers/copy_data_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work_item:, target_namespace:, target_work_item_type:, current_user: nil, params: {}, overwritten_params: {}) ⇒ CopyDataHandler

rubocop:disable Layout/LineLength – Keyword arguments are making the line a bit longer



11
12
13
14
15
16
17
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
# File 'app/services/work_items/data_sync/handlers/copy_data_handler.rb', line 11

def initialize(work_item:, target_namespace:, target_work_item_type:, current_user: nil, params: {}, overwritten_params: {})
  @work_item = work_item
  @target_namespace = target_namespace
  @target_work_item_type = target_work_item_type
  @current_user = current_user
  @params = params
  @operation = params.delete(:operation)

  @create_params = {
    id: nil,
    iid: nil,
    created_at: work_item.created_at,
    updated_at: work_item.updated_at,
    updated_by_id: work_item.updated_by_id,
    state_id: work_item.state_id,
    closed_at: work_item.closed_at,
    closed_by_id: work_item.closed_by_id,
    duplicated_to_id: work_item.duplicated_to_id,
    moved_to_id: work_item.moved_to_id,
    promoted_to_epic_id: work_item.promoted_to_epic_id,
    external_key: work_item.external_key,
    upvotes_count: work_item.upvotes_count,
    blocking_issues_count: work_item.blocking_issues_count,
    work_item_type: target_work_item_type,
    project_id: project&.id,
    namespace_id: target_namespace.id,
    title: work_item.title,
    author_id: work_item.author_id,
    relative_position: relative_position,
    confidential: work_item.confidential,
    cached_markdown_version: work_item.cached_markdown_version,
    lock_version: work_item.lock_version,
    service_desk_reply_to: service_desk_reply_to,
    imported_from: :none
  }.merge(overwritten_params)
end

Instance Attribute Details

#create_paramsObject (readonly)

Returns the value of attribute create_params.



7
8
9
# File 'app/services/work_items/data_sync/handlers/copy_data_handler.rb', line 7

def create_params
  @create_params
end

#current_userObject (readonly)

Returns the value of attribute current_user.



7
8
9
# File 'app/services/work_items/data_sync/handlers/copy_data_handler.rb', line 7

def current_user
  @current_user
end

#operationObject (readonly)

Returns the value of attribute operation.



7
8
9
# File 'app/services/work_items/data_sync/handlers/copy_data_handler.rb', line 7

def operation
  @operation
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'app/services/work_items/data_sync/handlers/copy_data_handler.rb', line 7

def params
  @params
end

#target_namespaceObject (readonly)

Returns the value of attribute target_namespace.



7
8
9
# File 'app/services/work_items/data_sync/handlers/copy_data_handler.rb', line 7

def target_namespace
  @target_namespace
end

#target_work_item_typeObject (readonly)

Returns the value of attribute target_work_item_type.



7
8
9
# File 'app/services/work_items/data_sync/handlers/copy_data_handler.rb', line 7

def target_work_item_type
  @target_work_item_type
end

#work_itemObject (readonly)

Returns the value of attribute work_item.



7
8
9
# File 'app/services/work_items/data_sync/handlers/copy_data_handler.rb', line 7

def work_item
  @work_item
end

Instance Method Details

#executeObject

rubocop:enable Layout/LineLength



49
50
51
52
53
54
55
56
57
58
# File 'app/services/work_items/data_sync/handlers/copy_data_handler.rb', line 49

def execute
  # create the new work item
  ::WorkItems::DataSync::BaseCreateService.new(
    original_work_item: work_item,
    operation: operation,
    container: target_namespace,
    current_user: current_user,
    params: create_params.merge(params)
  ).execute(skip_system_notes: skip_system_notes?)
end