From 8e37f3dc5f4b28084adb8be4e681f4731ff71b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Bol=C3=ADvar?= Date: Wed, 11 Dec 2024 15:43:54 +0100 Subject: [PATCH] Fix proposal export error with deleted users --- .../proposals/proposal_serializer.rb | 27 +++++++++++++++++++ config/initializers/decidim_overrides.rb | 1 + spec/lib/overrides_spec.rb | 1 + 3 files changed, 29 insertions(+) create mode 100644 app/lib/decidim/overrides/proposals/proposal_serializer.rb diff --git a/app/lib/decidim/overrides/proposals/proposal_serializer.rb b/app/lib/decidim/overrides/proposals/proposal_serializer.rb new file mode 100644 index 000000000..6633cd3c4 --- /dev/null +++ b/app/lib/decidim/overrides/proposals/proposal_serializer.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Decidim + module Overrides + module Proposals + module ProposalSerializer + private + + def author_url(author) + if author.respond_to?(:nickname) + profile_url(author) # is a Decidim::User or Decidim::UserGroup + elsif author.respond_to?(:title) + meeting_url(author) # is a Decidim::Meetings::Meeting + else + root_url # is a Decidim::Organization + end + end + + def profile_url(author) + return "" if author.respond_to?(:deleted?) && author.deleted? + + Decidim::Core::Engine.routes.url_helpers.profile_url(author.nickname, host:) + end + end + end + end +end diff --git a/config/initializers/decidim_overrides.rb b/config/initializers/decidim_overrides.rb index 3df4c8b2c..000a4299f 100644 --- a/config/initializers/decidim_overrides.rb +++ b/config/initializers/decidim_overrides.rb @@ -6,6 +6,7 @@ Decidim::SearchResourceFieldsMapper.prepend(Decidim::Overrides::SearchResourceFieldsMapper) Decidim::Initiatives::InitiativeMetadataGCell.include(Decidim::Initiatives::InitiativeMetadataGCellOverride) Decidim::Forms::UserAnswersSerializer.prepend(Decidim::Overrides::Forms::UserAnswersSerializer) + Decidim::Proposals::ProposalSerializer.prepend(Decidim::Overrides::Proposals::ProposalSerializer) Decidim::Initiative.include(Decidim::InitiativeOverride) Decidim::Accountability::Result.include(Decidim::Accountability::ResultOverride) Decidim::Accountability::ResultsCalculator.include(Decidim::Accountability::ResultsCalculatorOverride) diff --git a/spec/lib/overrides_spec.rb b/spec/lib/overrides_spec.rb index 26b3da048..99ccc0b71 100644 --- a/spec/lib/overrides_spec.rb +++ b/spec/lib/overrides_spec.rb @@ -114,6 +114,7 @@ { package: "decidim-proposals", files: { + "/lib/decidim/proposals/proposal_serializer.rb" => "ea339213f4f296aaafa3708dcd5c37c4", # remove once the solution of this PR is present https://github.com/decidim/decidim/pull/13592 "/app/helpers/decidim/proposals/application_helper.rb" => "c17dd875a166cd0cd3c09b0e596ebef5", "/app/presenters/decidim/proposals/proposal_presenter.rb" => "bbc7cee02125c1f8cf909219e48af337" }