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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#40228] added error handling for creating file links
Eric Schubert970f00ae054c
diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 8f03f45ed39..9c9f77b92d3 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1276,6 +1276,7 @@ en:error_enterprise_token_invalid_domain: "The Enterprise Edition is not active. Your Enterprise token's domain (%{actual}) does not match the system's host name (%{expected})."error_failed_to_delete_entry: 'Failed to delete this entry.'error_in_dependent: "Error attempting to alter dependent object: %{dependent_class} #%{related_id} - %{related_subject}: %{error}"+ error_in_new_dependent: "Error attempting to create dependent object: %{dependent_class} - %{related_subject}: %{error}"error_invalid_selected_value: "Invalid selected value."error_journal_attribute_not_present: "Journal does not contain attribute %{attribute}."error_pdf_export_too_many_columns: "Too many columns selected for the PDF export. Please reduce the number of columns."diff --git a/lib/api/utilities/endpoints/modify.rb b/lib/api/utilities/endpoints/modify.rbindex 29e424012e9..209c8a72bf1 100644--- a/lib/api/utilities/endpoints/modify.rb+++ b/lib/api/utilities/endpoints/modify.rb@@ -36,6 +36,12 @@ module APIendend+ protected++ def build_error_from_result(result)+ ActiveModel::Errors.new result+ end+privatedef present_success(_request, _call)@@ -56,7 +62,7 @@ module APIenddef merge_dependent_errors(call)- errors = ActiveModel::Errors.new call.result+ errors = build_error_from_result(call.result)call.dependent_results.each do |dr|dr.errors.full_messages.each do |full_message|@@ -68,8 +74,15 @@ module APIenddef dependent_error_message(result, full_message)+ key =+ if result.id.blank?+ :error_in_new_dependent+ else+ :error_in_dependent+ end+I18n.t(- :error_in_dependent,+ key,dependent_class: result.model_name.human,related_id: result.id,# TODO: Make it more robust, as not every model has a 'name' attribute (e.g. fall back to collection index?)diff --git a/modules/storages/lib/api/v3/file_links/create_endpoint.rb b/modules/storages/lib/api/v3/file_links/create_endpoint.rbindex a62ed8b665c..2fc8be9b7db 100644--- a/modules/storages/lib/api/v3/file_links/create_endpoint.rb+++ b/modules/storages/lib/api/v3/file_links/create_endpoint.rb@@ -24,6 +24,12 @@ module API::V3::FileLinks)end+ protected++ def build_error_from_result(result)+ ActiveModel::Errors.new result.first+ end+privatedef params_modifierdiff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rbindex 5d98312f6ac..686e956c0b5 100644--- a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb@@ -174,7 +174,9 @@ describe 'API v3 file links resource', type: :request do}end- it_behaves_like 'invalid request body'+ it_behaves_like 'constraint violation' do+ let(:message) { 'Storage is invalid' }+ endendend