Skip to content

Commit

Permalink
feat: Export proposals attachments url (#126)
Browse files Browse the repository at this point in the history
* fix: Export proposals rake task

* fix: Export attachments url in proposal serializer

* revert: Remove dummy rake task

* spec: Ensure attachments_urls key is serialized
  • Loading branch information
Quentinchampenois authored Dec 4, 2024
1 parent 4573247 commit c5367b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ scaleway:
region: fr-par
bucket: <%= Rails.application.secrets.dig(:scaleway, :bucket_name) %>
force_path_style: true
public: true

# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def serialize
},
comments: proposal.comments_count,
attachments: proposal.attachments.count,
attachment_urls: attachment_urls,
followers: proposal.followers.count,
published_at: proposal.published_at,
url: url,
Expand All @@ -45,6 +46,12 @@ def serialize
}
}
end

def attachment_urls
proposal.attachments.map do |attc|
Rails.application.routes.url_helpers.rails_blob_url(attc.file.blob, host: proposal.participatory_space.organization.host)
end.join(",")
end
end

Decidim::Proposals::ProposalSerializer.class_eval do
Expand Down
4 changes: 4 additions & 0 deletions spec/services/decidim/proposals/proposal_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ module Proposals
expect(serialized).to include(attachments: proposal.attachments.count)
end

it "serializes the attachments urls" do
expect(serialized).to include(:attachment_urls)
end

it "serializes the endorsements" do
expect(serialized[:endorsements]).to include(total_count: proposal.endorsements.count)
expect(serialized[:endorsements]).to include(user_endorsements: proposal.endorsements.for_listing.map { |identity| identity.normalized_author&.name })
Expand Down

0 comments on commit c5367b2

Please sign in to comment.