Class: DesignManagement::CopyDesignCollection::CopyService

Inherits:
DesignService show all
Defined in:
app/services/design_management/copy_design_collection/copy_service.rb

Instance Attribute Summary

Attributes inherited from DesignService

#issue

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from DesignService

#collection, #project, #repository, #target_branch

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?

Constructor Details

#initialize(project, user, params = {}) ⇒ CopyService

rubocop: disable CodeReuse/ActiveRecord


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/design_management/copy_design_collection/copy_service.rb', line 9

def initialize(project, user, params = {})
  super

  @target_issue = params.fetch(:target_issue)
  @target_project = @target_issue.project
  @target_repository = @target_project.design_repository
  @target_design_collection = @target_issue.design_collection
  @temporary_branch = "CopyDesignCollectionService_#{SecureRandom.hex}"
  # The user who triggered the copy may not have permissions to push
  # to the design repository.
  @git_user = @target_project.first_owner

  @designs = DesignManagement::Design.unscoped.where(issue: issue).order(:id).load
  @versions = DesignManagement::Version.unscoped.where(issue: issue).order(:id).includes(:designs).load

  @sha_attribute = Gitlab::Database::ShaAttribute.new
  @shas = []
  @event_enum_map = DesignManagement::DesignAction::EVENT_FOR_GITALY_ACTION.invert
end

Instance Method Details

#executeObject

rubocop: enable CodeReuse/ActiveRecord


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/services/design_management/copy_design_collection/copy_service.rb', line 30

def execute
  return error('User cannot copy design collection to issue') unless user_can_copy?
  return error('Target design collection must first be queued') unless target_design_collection.copy_in_progress?
  return error('Design collection has no designs') if designs.empty?
  return error('Target design collection already has designs') unless target_design_collection.empty?

  with_temporary_branch do
    copy_commits!

    ApplicationRecord.transaction do
      design_ids = copy_designs!
      version_ids = copy_versions!
      copy_actions!(design_ids, version_ids)
      link_lfs_files!
      copy_notes!(design_ids)
      finalize!
    end
  end

  ServiceResponse.success
rescue StandardError => error
  log_exception(error)

  target_design_collection.error_copy!

  error('Designs were unable to be copied successfully')
end