Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix export job using attachment service

Oliver Günther4c3307f8aa27
diff --git a/app/workers/work_packages/exports/export_job.rb b/app/workers/work_packages/exports/export_job.rb
index f98f10ef079..c0a4544b052 100644
--- a/app/workers/work_packages/exports/export_job.rb
+++ b/app/workers/work_packages/exports/export_job.rb
@@ -88,16 +88,23 @@ module WorkPackages
end
end
- def store_attachment(storage, file)
- attachment = Attachments::CreateService
- .new(storage, author: User.current)
- .call(uploaded_file: file, description: '')
+ def store_attachment(container, file)
+ call = Attachments::CreateService
+ .new(user: User.current)
+ .call(container: container, file: file, filename: File.basename(file), description: '')
- download_url = ::API::V3::Utilities::PathHelper::ApiV3Path.attachment_content(attachment.id)
+ call.on_success do
+ download_url = ::API::V3::Utilities::PathHelper::ApiV3Path.attachment_content(call.result.id)
- upsert_status status: :success,
- message: I18n.t('export.succeeded'),
- payload: download_payload(download_url)
+ upsert_status status: :success,
+ message: I18n.t('export.succeeded'),
+ payload: download_payload(download_url)
+ end
+
+ call.on_failure do
+ upsert_status status: :failure,
+ message: I18n.t('export.failed', message: call.message)
+ end
end
end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index d5f11428190..09e42c08dc8 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1266,6 +1266,7 @@ en:
export:
your_work_packages_export: "Your work packages export"
succeeded: "The export has completed successfully."
+ failed: "The export has failed: %{message}"
format:
atom: "Atom"
csv: "CSV"