Class: Import::SourceUsers::BulkReassignFromCsvService
- Inherits:
-
Object
- Object
- Import::SourceUsers::BulkReassignFromCsvService
- Defined in:
- app/services/import/source_users/bulk_reassign_from_csv_service.rb
Instance Method Summary collapse
- #async_execute ⇒ ServiceResponse
- #execute ⇒ ServiceResponse
-
#initialize(current_user, namespace, upload) ⇒ BulkReassignFromCsvService
constructor
A new instance of BulkReassignFromCsvService.
Constructor Details
#initialize(current_user, namespace, upload) ⇒ BulkReassignFromCsvService
Returns a new instance of BulkReassignFromCsvService.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/services/import/source_users/bulk_reassign_from_csv_service.rb', line 6 def initialize(current_user, namespace, upload) @upload = upload @current_user = current_user @namespace = namespace @reassignment_stats = { skipped: 0, matched: 0, failed: 0 } @reassignment_error_csv_data = [] raw_csv_data = upload.retrieve_uploader.file.read @csv_validator = ::Import::UserMapping::ReassignmentCsvValidator.new(raw_csv_data) end |
Instance Method Details
#async_execute ⇒ ServiceResponse
23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/import/source_users/bulk_reassign_from_csv_service.rb', line 23 def async_execute return ServiceResponse.error(message: csv_validator.formatted_errors) unless csv_validator.valid? Import::UserMapping::AssignmentFromCsvWorker.perform_async( current_user.id, namespace.id, upload.id ) ServiceResponse.success end |
#execute ⇒ ServiceResponse
36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/import/source_users/bulk_reassign_from_csv_service.rb', line 36 def execute return ServiceResponse.error(message: :invalid_csv_format) unless csv_validator.valid? process_csv ServiceResponse.success(payload: { stats: reassignment_stats, failures_csv_data: failure_csv }) end |