1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/workers/members_import_worker.rb
Sylvain ff5de97c92 import new users from CSV and view results in app
TODO:
 - update users though CSV
2019-09-26 17:05:57 +02:00

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