Class: Decidim::DownloadYourDataExporter

Inherits:
Object
  • Object
show all
Includes:
TranslatableAttributes
Defined in:
decidim-core/app/services/decidim/download_your_data_exporter.rb

Overview

Public: Generates a zip archive with data files ready to be persisted somewhere so users can download their data.

Constant Summary collapse

DEFAULT_EXPORT_FORMAT =
"CSV"
ZIP_FILE_NAME =
"download-your-data.zip"

Instance Method Summary collapse

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Constructor Details

#initialize(user, name, export_format = DEFAULT_EXPORT_FORMAT) ⇒ DownloadYourDataExporter

Public: Initializes the class.

user - The user to export the data from. name - The name of the export in private area export_format - The format of the data files inside the zip file. (CSV by default)



18
19
20
21
22
# File 'decidim-core/app/services/decidim/download_your_data_exporter.rb', line 18

def initialize(user, name, export_format = DEFAULT_EXPORT_FORMAT)
  @user = user
  @export_format = export_format
  @name = name
end

Instance Method Details

#exportObject

i18n-tasks-use t(“decidim.download_your_data.show.download_your_data”)



25
26
27
28
29
30
31
32
33
# File 'decidim-core/app/services/decidim/download_your_data_exporter.rb', line 25

def export
  user_export = user.private_exports.build
  user_export.export_type = name
  user_export.file.attach(io: data, filename: "#{name}.zip", content_type: "application/zip")
  user_export.expires_at = Decidim.download_your_data_expiry_time.from_now
  user_export. = {}
  user_export.save!
  user_export
end