mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
ff5de97c92
TODO: - update users though CSV
24 lines
795 B
Ruby
24 lines
795 B
Ruby
# frozen_string_literal: true
|
|
|
|
# Will parse the uploaded CSV file and save or update the members described in that file.
|
|
# This import will be asynchronously proceed by sidekiq and a notification will be sent to the requesting user when it's done.
|
|
class MembersImportWorker
|
|
include Sidekiq::Worker
|
|
|
|
def perform(import_id)
|
|
import = Import.find(import_id)
|
|
|
|
raise SecurityError, 'Not allowed to import' unless import.user.admin?
|
|
raise KeyError, 'Wrong worker called' unless import.category == 'members'
|
|
|
|
res = Members::ImportService.import(import)
|
|
|
|
import.results = res.to_yaml
|
|
import.save!
|
|
|
|
NotificationCenter.call type: :notify_admin_import_complete,
|
|
receiver: import.user,
|
|
attached_object: import
|
|
end
|
|
end
|