Sha256: 382402599548cd1d5cddb0f4b7079459baa245bb3e6d925129ef20943cb3f24d

Contents?: true

Size: 1.16 KB

Versions: 38

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    module Census
      module Admin
        class ExportAccessCodesJob < ApplicationJob
          queue_as :exports

          def perform(dataset, user)
            filename = "#{SecureRandom.urlsafe_base64}.zip"
            path = Rails.root.join("tmp/#{filename}")
            password = SecureRandom.urlsafe_base64

            ActiveRecord::Base.transaction do
              UpdateDataset.call(dataset, { status: :exporting_codes }, user)

              generate_zip_file(dataset, path, password)
              save_or_upload_file(dataset, path)
              ExportMailer.access_codes_export(user, dataset.voting, filename, password).deliver_later

              UpdateDataset.call(dataset, { status: :freeze }, user)
            end
          end

          private

          def generate_zip_file(dataset, path, password)
            AccessCodesExporter.new(dataset, path, password).export
          end

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

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
decidim-elections-0.28.4 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.27.9 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.28.3 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.27.8 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.28.2 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.27.7 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.28.1 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.27.6 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.26.10 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.26.9 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.28.0 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.27.5 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.28.0.rc5 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.28.0.rc4 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.26.8 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.27.4 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.27.3 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.26.7 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.26.5 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb
decidim-elections-0.27.2 app/jobs/decidim/votings/census/admin/export_access_codes_job.rb