diff --git a/decidim-debates/lib/decidim/debates/debate_serializer.rb b/decidim-debates/lib/decidim/debates/debate_serializer.rb index e9b59df5ef60a..b039231da4987 100644 --- a/decidim-debates/lib/decidim/debates/debate_serializer.rb +++ b/decidim-debates/lib/decidim/debates/debate_serializer.rb @@ -73,14 +73,16 @@ def author_name(author) def author_url(author) if author.respond_to?(:nickname) - profile_url(author.nickname) # is a Decidim::User or Decidim::UserGroup + profile_url(author) # is a Decidim::User or Decidim::UserGroup else root_url # is a Decidim::Organization end end - def profile_url(nickname) - Decidim::Core::Engine.routes.url_helpers.profile_url(nickname, host:) + def profile_url(author) + return "" if author.respond_to?(:deleted?) && author.deleted? + + Decidim::Core::Engine.routes.url_helpers.profile_url(author.nickname, host:) end def root_url diff --git a/decidim-debates/spec/services/decidim/open_data_exporter_spec.rb b/decidim-debates/spec/services/decidim/open_data_exporter_spec.rb index fb5ca77ec0669..74699b7366a28 100644 --- a/decidim-debates/spec/services/decidim/open_data_exporter_spec.rb +++ b/decidim-debates/spec/services/decidim/open_data_exporter_spec.rb @@ -34,6 +34,35 @@ it_behaves_like "open data exporter" end + describe "debates by deleted user" do + let(:resource_file_name) { "debates" } + let(:component) do + create(:debates_component, organization:, published_at: Time.current) + end + + let!(:deleted_user) { create(:user, :confirmed, :deleted, organization:) } + let!(:resource) { create(:debate, component:, author: deleted_user) } + + let(:second_component) do + create(:debates_component, organization:, published_at: Time.current) + end + let!(:second_resource) { create(:debate, :closed, component: second_component, author: deleted_user) } + + let(:resource_title) { "## debates" } + let(:help_lines) do + [ + "* id: The unique identifier of the debate", + "* conclusions: The conclusions of the debate if it was closed" + ] + end + let(:unpublished_component) do + create(:debates_component, organization:, published_at: nil) + end + let(:unpublished_resource) { create(:debate, component: unpublished_component) } + + it_behaves_like "open data exporter" + end + describe "debate_comments" do let(:resource_file_name) { "debate_comments" } let(:component) do diff --git a/decidim-meetings/config/locales/en.yml b/decidim-meetings/config/locales/en.yml index eeb9513ab95aa..f41ff36caa77d 100644 --- a/decidim-meetings/config/locales/en.yml +++ b/decidim-meetings/config/locales/en.yml @@ -712,6 +712,7 @@ en: address: The address of the meeting in case it is in person and has a physical location attachments: The number of attachments in this meeting attendees: The number of people attending this meeting + author: The data for the author of this meeting comments: The number of comments made in this meeting component: The component that the meeting belongs to contributions: The number of contributions in this meeting made by the atteendes diff --git a/decidim-meetings/lib/decidim/meetings/meeting_serializer.rb b/decidim-meetings/lib/decidim/meetings/meeting_serializer.rb index 8390c41accb55..01aa11ecbef9b 100644 --- a/decidim-meetings/lib/decidim/meetings/meeting_serializer.rb +++ b/decidim-meetings/lib/decidim/meetings/meeting_serializer.rb @@ -17,6 +17,9 @@ def initialize(meeting) def serialize { id: meeting.id, + author: { + **author_fields + }, participatory_space: { id: meeting.participatory_space.id, url: Decidim::ResourceLocatorPresenter.new(meeting.participatory_space).url @@ -53,6 +56,40 @@ def serialize attr_reader :meeting alias resource meeting + def author_fields + { + id: meeting.author.id, + name: author_name(meeting.author), + url: author_url(meeting.author) + } + end + + def author_name(author) + translated_attribute(author.name) + end + + def author_url(author) + if author.respond_to?(:nickname) + profile_url(author) # is a Decidim::User or Decidim::UserGroup + 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 + + def root_url + Decidim::Core::Engine.routes.url_helpers.root_url(host:) + end + + def host + resource.organization.host + end + def component meeting.component end diff --git a/decidim-meetings/spec/services/decidim/open_data_exporter_spec.rb b/decidim-meetings/spec/services/decidim/open_data_exporter_spec.rb index 4f089155f0ee0..3cb26643b592d 100644 --- a/decidim-meetings/spec/services/decidim/open_data_exporter_spec.rb +++ b/decidim-meetings/spec/services/decidim/open_data_exporter_spec.rb @@ -27,6 +27,27 @@ it_behaves_like "open data exporter" end + describe "meeting created by deleted user" do + let!(:deleted_user) { create(:user, :confirmed, :deleted, organization:) } + let(:resource_file_name) { "meetings" } + let(:component) do + create(:meeting_component, organization:, published_at: Time.current) + end + let!(:resource) { create(:meeting, component:, author: deleted_user) } + let(:resource_title) { "## meetings" } + let(:help_lines) do + [ + "* id: The unique identifier of the meeting" + ] + end + let(:unpublished_component) do + create(:meeting_component, organization:, published_at: nil) + end + let(:unpublished_resource) { create(:meeting, component: unpublished_component, author: deleted_user) } + + it_behaves_like "open data exporter" + end + describe "meeting_comments" do let(:resource_file_name) { "meeting_comments" } let(:component) do diff --git a/decidim-proposals/lib/decidim/proposals/proposal_serializer.rb b/decidim-proposals/lib/decidim/proposals/proposal_serializer.rb index 241a12e5d4892..c0dde40e29658 100644 --- a/decidim-proposals/lib/decidim/proposals/proposal_serializer.rb +++ b/decidim-proposals/lib/decidim/proposals/proposal_serializer.rb @@ -128,7 +128,7 @@ def author_name(author) def author_url(author) if author.respond_to?(:nickname) - profile_url(author.nickname) # is a Decidim::User or Decidim::UserGroup + profile_url(author) # is a Decidim::User or Decidim::UserGroup elsif author.respond_to?(:title) meeting_url(author) # is a Decidim::Meetings::Meeting else @@ -136,8 +136,10 @@ def author_url(author) end end - def profile_url(nickname) - Decidim::Core::Engine.routes.url_helpers.profile_url(nickname, host:) + def profile_url(author) + return "" if author.respond_to?(:deleted?) && author.deleted? + + Decidim::Core::Engine.routes.url_helpers.profile_url(author.nickname, host:) end def meeting_url(meeting) diff --git a/decidim-proposals/spec/services/decidim/open_data_exporter_spec.rb b/decidim-proposals/spec/services/decidim/open_data_exporter_spec.rb index 6845bfeaa083b..fc4ec24c46f24 100644 --- a/decidim-proposals/spec/services/decidim/open_data_exporter_spec.rb +++ b/decidim-proposals/spec/services/decidim/open_data_exporter_spec.rb @@ -27,6 +27,27 @@ it_behaves_like "open data exporter" end + describe "proposals by deleted user" do + let(:resource_file_name) { "proposals" } + let(:component) do + create(:proposal_component, organization:, published_at: Time.current) + end + let!(:deleted_user) { create(:user, :confirmed, :deleted, organization:) } + let!(:resource) { create(:proposal, component:, users: [deleted_user]) } + let(:resource_title) { "## proposals" } + let(:help_lines) do + [ + "* id: The unique identifier for the proposal" + ] + end + let(:unpublished_component) do + create(:proposal_component, organization:, published_at: nil) + end + let(:unpublished_resource) { create(:proposal, component: unpublished_component, users: [deleted_user]) } + + it_behaves_like "open data exporter" + end + describe "proposal_comments" do let(:resource_file_name) { "proposal_comments" } let(:component) do