2019-04-03 17:39:45 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Will generate an excel file containing all the users.
|
|
|
|
# This file will be asynchronously generated by sidekiq and a notification will be sent to the requesting user when it's done.
|
2016-07-27 17:00:06 +02:00
|
|
|
class UsersExportWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform(export_id)
|
|
|
|
export = Export.find(export_id)
|
|
|
|
|
2019-04-03 17:39:45 +02:00
|
|
|
raise SecurityError, 'Not allowed to export' unless export.user.admin?
|
|
|
|
raise KeyError, 'Wrong worker called' unless export.category == 'users'
|
2016-07-27 17:00:06 +02:00
|
|
|
|
|
|
|
service = UsersExportService.new
|
|
|
|
method_name = "export_#{export.export_type}"
|
|
|
|
|
2019-04-03 17:39:45 +02:00
|
|
|
return unless %w[members subscriptions reservations].include?(export.export_type) && service.respond_to?(method_name)
|
2016-07-27 17:00:06 +02:00
|
|
|
|
2019-04-03 17:39:45 +02:00
|
|
|
service.public_send(method_name, export)
|
2016-07-27 17:00:06 +02:00
|
|
|
|
2019-04-03 17:39:45 +02:00
|
|
|
NotificationCenter.call type: :notify_admin_export_complete,
|
|
|
|
receiver: export.user,
|
|
|
|
attached_object: export
|
2016-07-27 17:00:06 +02:00
|
|
|
end
|
|
|
|
end
|