Class: Projects::ImportExport::RelationImportService
- Inherits:
-
Object
- Object
- Projects::ImportExport::RelationImportService
- Includes:
- Services::ReturnServiceResponses
- Defined in:
- app/services/projects/import_export/relation_import_service.rb
Constant Summary collapse
- IMPORTABLE_RELATIONS =
%w[issues merge_requests milestones ci_pipelines].freeze
Instance Method Summary collapse
-
#execute ⇒ Services::ServiceResponse
Checks the validity of the chosen project and triggers the re-import of the chosen relation.
-
#initialize(current_user:, params:) ⇒ RelationImportService
constructor
Creates a new RelationImportService.
Methods included from Services::ReturnServiceResponses
Constructor Details
#initialize(current_user:, params:) ⇒ RelationImportService
Creates a new RelationImportService.
19 20 21 22 |
# File 'app/services/projects/import_export/relation_import_service.rb', line 19 def initialize(current_user:, params:) @current_user = current_user @params = params end |
Instance Method Details
#execute ⇒ Services::ServiceResponse
Checks the validity of the chosen project and triggers the re-import of the chosen relation.
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 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/services/projects/import_export/relation_import_service.rb', line 28 def execute return error(_('Project not found'), :not_found) unless project unless relation_valid? return error( format( _('Imported relation must be one of %{relations}'), relations: IMPORTABLE_RELATIONS.to_sentence(last_word_connector: ', or ') ), :bad_request ) end return error(_('You are not authorized to perform this action'), :forbidden) unless user_permitted? return error(_('A relation import is already in progress for this project'), :conflict) if import_in_progress? tracker = create_status_tracker unless tracker.persisted? return error( format( _('Relation import could not be created: %{errors}'), errors: tracker.errors..to_sentence ), :bad_request ) end attach_import_file Projects::ImportExport::RelationImportWorker.perform_async( tracker.id, current_user.id ) success(tracker) end |