Class: DesignManagement::SaveDesignsService

Inherits:
DesignService show all
Includes:
OnSuccessCallbacks, RunsDesignActions
Defined in:
app/services/design_management/save_designs_service.rb

Constant Summary collapse

MAX_FILES =
10

Constants included from RunsDesignActions

RunsDesignActions::NoActions

Instance Attribute Summary

Attributes inherited from DesignService

#issue

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from OnSuccessCallbacks

#on_success, #success

Methods included from RunsDesignActions

#run_actions

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 = {}) ⇒ SaveDesignsService

Returns a new instance of SaveDesignsService.


10
11
12
13
14
# File 'app/services/design_management/save_designs_service.rb', line 10

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

  @files = params.fetch(:files)
end

Instance Method Details

#executeObject


16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/design_management/save_designs_service.rb', line 16

def execute
  return error("Not allowed!") unless can_create_designs?
  return error("Only #{MAX_FILES} files are allowed simultaneously") if files.size > MAX_FILES

  uploaded_designs, version = upload_designs!
  skipped_designs = designs - uploaded_designs

  create_events
  success({ designs: uploaded_designs, version: version, skipped_designs: skipped_designs })
rescue ::ActiveRecord::RecordInvalid => e
  error(e.message)
end