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 all 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,18 @@
# frozen_string_literal: true

module Lib::Decidim::Proposals::ProposalSerializerDecorator
def self.decorate
Decidim::Proposals::ProposalSerializer.class_eval do
alias_method :original_serialize, :serialize

# Add authors to proposal exportation
def serialize
tramuntanal marked this conversation as resolved.
Show resolved Hide resolved
original_serialize.merge({
authors_names: proposal.authors.pluck(:name)
})
end
end
end
end

::Lib::Decidim::Proposals::ProposalSerializerDecorator.decorate
13 changes: 12 additions & 1 deletion docs/HOW_TO_UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,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 @@ -197,6 +197,17 @@ These are custom modules and this is what you have to keep in mind when updating

* `decorators/decidim/participatory_space_context_decorator.rb`
* 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
* Only the `#can_participate?(user)` has been modified
* probably removable from Decidim v0.24

Following ones, for some addings or template overrides:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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
end
end
end
end
# rubocop:enable RSpec/MultipleMemoizedHelpers
Loading