1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/workers/members_import_worker.rb

24 lines
795 B
Ruby
Raw Normal View History

2019-09-25 16:37:42 +02:00
# 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!
2019-09-25 16:37:42 +02:00
NotificationCenter.call type: :notify_admin_import_complete,
receiver: import.user,
attached_object: import
end
end