Skip to content

Commit

Permalink
Merge pull request #491 from gencat/add/author_in_export_proposals
Browse files Browse the repository at this point in the history
Add authors to proposals exportation
  • Loading branch information
laurajaime authored Nov 13, 2024
2 parents 04953f0 + 19f765b commit cab1351
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
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
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

0 comments on commit cab1351

Please sign in to comment.