Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authors to proposals exportation #491

Merged
merged 8 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

module Decidim::Proposals::ProposalSerializerDecorator
def self.decorate
Decidim::Proposals::ProposalSerializer.class_eval do
# Add authors to proposal exportation
def serialize
tramuntanal marked this conversation as resolved.
Show resolved Hide resolved
{
id: proposal.id,
category: {
id: proposal.category.try(:id),
name: proposal.category.try(:name) || empty_translatable
},
scope: {
id: proposal.scope.try(:id),
name: proposal.scope.try(:name) || empty_translatable
},
participatory_space: {
id: proposal.participatory_space.id,
url: Decidim::ResourceLocatorPresenter.new(proposal.participatory_space).url
},
component: { id: component.id },
title: proposal.title,
body: convert_to_plain_text(proposal.body),
address: proposal.address,
latitude: proposal.latitude,
longitude: proposal.longitude,
state: proposal.state.to_s,
reference: proposal.reference,
answer: ensure_translatable(proposal.answer),
supports: proposal.proposal_votes_count,
endorsements: {
total_count: proposal.endorsements.size,
user_endorsements: user_endorsements
},
comments: proposal.comments_count,
attachments: proposal.attachments.size,
followers: proposal.follows.size,
published_at: proposal.published_at,
url: url,
meeting_urls: meetings,
related_proposals: related_proposals,
is_amend: proposal.emendation?,
original_proposal: {
title: proposal&.amendable&.title,
url: original_proposal_url
},
# Gencat customization
authors_names: proposal.authors.pluck(:name),
authors_emails: proposal.authors.pluck(:email)
# Gencat customization
}
end
end
end
end

::Decidim::Proposals::ProposalSerializerDecorator.decorate
6 changes: 5 additions & 1 deletion docs/HOW_TO_UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ These are custom modules and this is what you have to keep in mind when updating

#### 6. Also, there are custom files in the application "participa.gencat.cat".

##### Modified files:
##### Modified files:

With decorator pattern:

Expand All @@ -198,6 +198,10 @@ These are custom modules and this is what you have to keep in mind when updating
* Override to allow private space users to acces public view
* probably removable from Decidim v0.24

* `decorators/lib/decidim/proposals/proposal_serializer_decorator.rb`
* Override to export proposal emails and names from authors
* probably removable from Decidim v0.28 (remember remove test too)

* `lib/decidim/has_private_users.rb`
* Override to allow private space users to acces public view
* Could not use a decorator so the whole class has been copied
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

require "rails_helper"

# rubocop:disable RSpec/MultipleMemoizedHelpers
module Decidim
module Proposals
describe ProposalSerializer do
subject do
described_class.new(proposal)
end

let!(:proposal) { create(:proposal, :accepted, body: body) }
let!(:category) { create(:category, participatory_space: component.participatory_space) }
let!(:scope) { create(:scope, organization: component.participatory_space.organization) }
let(:participatory_process) { component.participatory_space }
let(:component) { proposal.component }

let!(:meetings_component) { create(:component, manifest_name: "meetings", participatory_space: participatory_process) }
let(:meetings) { create_list(:meeting, 2, :published, component: meetings_component) }

let!(:proposals_component) { create(:component, manifest_name: "proposals", participatory_space: participatory_process) }
let(:other_proposals) { create_list(:proposal, 2, component: proposals_component) }
let(:body) { Decidim::Faker::Localized.localized { ::Faker::Lorem.sentences(number: 3).join("\n") } }

let(:expected_answer) do
answer = proposal.answer
Decidim.available_locales.each_with_object({}) do |locale, result|
result[locale.to_s] = if answer.is_a?(Hash)
answer[locale.to_s] || ""
else
""
end
end
end

before do
proposal.update!(category: category)
proposal.update!(scope: scope)
proposal.link_resources(meetings, "proposals_from_meeting")
proposal.link_resources(other_proposals, "copied_from_component")
end

describe "#serialize" do
let(:serialized) { subject.serialize }

it "serializes the authors names" do
expect(serialized).to include(authors_names: proposal.authors.pluck(:name))
end

it "serializes the authors emails" do
expect(serialized).to include(authors_emails: proposal.authors.pluck(:email))
end
end
end
end
end
# rubocop:enable RSpec/MultipleMemoizedHelpers
Loading