Sha256: 0e1ac376a26c244402a4a177de088db8b9c897a216934e1a14722e398baa8841

Contents?: true

Size: 882 Bytes

Versions: 7

Compression:

Stored size: 882 Bytes

Contents

# frozen_string_literal: true

module Decidim
  class DownloadYourDataExportJob < ApplicationJob
    queue_as :default

    def perform(user, export_format = ::Decidim::DownloadYourDataExporter::DEFAULT_EXPORT_FORMAT)
      filename = "#{SecureRandom.urlsafe_base64}.zip"
      path = Rails.root.join("tmp/#{filename}")
      password = SecureRandom.urlsafe_base64

      generate_zip_file(user, path, password, export_format)
      save_or_upload_file(user, path)

      ExportMailer.download_your_data_export(user, filename, password).deliver_later
    end

    private

    def generate_zip_file(user, path, password, export_format)
      DownloadYourDataExporter.new(user, path, password, export_format).export
    end

    def save_or_upload_file(user, path)
      user.download_your_data_file.attach(io: File.open(path, "rb"), filename: File.basename(path))
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-core-0.27.4 app/jobs/decidim/download_your_data_export_job.rb
decidim-core-0.27.3 app/jobs/decidim/download_your_data_export_job.rb
decidim-core-0.27.2 app/jobs/decidim/download_your_data_export_job.rb
decidim-core-0.27.1 app/jobs/decidim/download_your_data_export_job.rb
decidim-core-0.27.0 app/jobs/decidim/download_your_data_export_job.rb
decidim-core-0.27.0.rc2 app/jobs/decidim/download_your_data_export_job.rb
decidim-core-0.27.0.rc1 app/jobs/decidim/download_your_data_export_job.rb