# frozen_string_literal: true module Reports class DocxJob < ApplicationJob include InputSanitizeHelper queue_as :reports def perform(report, user, team, root_url) file = Tempfile.new(['report', '.docx']) begin docx = Caracal::Document.new(file.path) Reports::Docx.new(report, docx, user: user, team: team, scinote_url: root_url).draw docx.save report.docx_file.attach(io: file, filename: 'report.docx') report.update!(docx_file_processing: false) report_path = Rails.application.routes.url_helpers.reports_path notification = Notification.create( type_of: :deliver, title: I18n.t('projects.reports.index.generation.completed_notification_title'), message: I18n.t('projects.reports.index.generation.completed_notification_message', report_link: "#{sanitize_input(report.name)}", team_name: sanitize_input(report.team.name)) ) notification.create_user_notification(user) ensure file.close file.unlink end end end end