Skip to content

Fix single attachment with title#13795

Merged
alecslupu merged 3 commits intodecidim:developfrom
mainio:fix/single-attachment-with-title
Jan 22, 2025
Merged

Fix single attachment with title#13795
alecslupu merged 3 commits intodecidim:developfrom
mainio:fix/single-attachment-with-title

Conversation

@ahukkanen
Copy link
Copy Markdown
Contributor

🎩 What? Why?

Currently having a single attachment with title breaks the parameters parsing in Rails. The issue is further explained at #13792 and the added spec tests this situation.

📌 Related Issues

Testing

  • Take the spec from this PR and run it against current develop
  • See the spec fail (ActionController::BadRequest: Invalid request parameters: expected Hash (got String) for param add_image'`)
  • Take the fix from this branch and recompile the assets
  • See the spec pass

@github-actions github-actions bot added module: core type: fix PRs that implement a fix for a bug labels Dec 27, 2024
github-actions[bot]
github-actions bot previously approved these changes Dec 27, 2024
github-actions[bot]
github-actions bot previously approved these changes Dec 27, 2024
Copy link
Copy Markdown
Contributor

@alecslupu alecslupu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried the changes in this PR and seems to work ok.
I have also tried to change the proposal / edit_form_fields as suggested in the bug report, and we still have an error (different).
Could you also patch the decidim-core/app/commands/decidim/multiple_attachments_methods.rb file so that we have a successful upload?

image

@ahukkanen
Copy link
Copy Markdown
Contributor Author

@alecslupu I don't think it can be solved in the multiple_attachment_methods.rb because it is meant for multiple attachments. In this case we are trying to add a single attachment.

For a quick fix how you can test with the proposals:

  1. Implement the changes to the _form.html.erb described at Single attachment with title does work #13792
  2. Change this line:
    to:
      attribute :documents, Integer
      attribute :add_documents, Hash
  1. Change this line:
    @form.add_documents.compact_blank.each do |attachment|

    to:
      [@form.add_documents].each do |attachment|
  1. Change this line:
    to:
      [@form.documents].compact.each do |document|
  1. Change this line:
    to:
        @form.documents = document

If these changes were implemented to the multiple_attachment_methods.rb, it would break multiple attachments which is not desired.

Single attachment needs to be handled differently than multiple attachments. Otherwise I would have suggested changing Decidim::MultipleAttachmentsMethods to Decidim::AttachmentMethods but that does not work in this case as the attribute name in that module is hard coded to attachment and it would require more changes to change that.

@alecslupu
Copy link
Copy Markdown
Contributor

@alecslupu I don't think it can be solved in the multiple_attachment_methods.rb because it is meant for multiple attachments. In this case we are trying to add a single attachment.
@ahukkanen I understand ... But is there any way of guarding this to avoid this kind of error in the future ?

@ahukkanen
Copy link
Copy Markdown
Contributor Author

@ahukkanen I understand ... But is there any way of guarding this to avoid this kind of error in the future ?

It would be refactoring the Decidim::AttachmentMethods to support any attribute name. Now it only supports attachment as the attribute name and also does not support multiple single file attributes.

Also Decidim::MultipleAttachmentsMethods assumes the attribute name on the form is always documents, which might not be always the case. I think the refactor should apply to both of these.

In the actual case where this was noticed (ideas module), the logic for handling the attachments during form submission is customized for the particular case. Of course, it would be nice if we could apply the logic from the core.

@alecslupu alecslupu added release: v0.28 Issues or PRs that need to be tackled for v0.28 release: v0.29 Issues or PRs that need to be tackled for v0.29 labels Jan 22, 2025
@alecslupu alecslupu merged commit c8564f5 into decidim:develop Jan 22, 2025
@ahukkanen ahukkanen deleted the fix/single-attachment-with-title branch January 22, 2025 13:55
entantoencuanto added a commit that referenced this pull request Jan 24, 2025
* develop: (30 commits)
  Change hardcoded english in seeds (#13917)
  Allow importing accountability results from a Proposals component (#13817)
  Remove user interests (#13910)
  Move remaining categories from some resources to taxonomies (#13838)
  Fix translation issue on import projects mailer (#13894)
  Update DownloadYourData exports for decidim-debates (#13895)
  Allow admins to publish the questions' answers in surveys (#13786)
  Fix flaky spec in autocomplete (#13901)
  Refine taxonomy filters (part 2) (#13725)
  Fix single attachment with title (#13795)
  Fix incorrect breadcrumb encoding on mobile and tablet (#13891)
  Add string for unpublish survey admin log message (#13890)
  Fix ux meeting date location (#13872)
  New Crowdin updates (#13767)
  Fix deleted user error in schema (#13681)
  Remove assembly types from user interaction (#13881)
  Remove participatory process types from user interaction (#13880)
  Lock concurrent-ruby to 1.3.4 (#13879)
  Fix taxonomy serialization for export/imports (#13857)
  Adjust form upload label changes (#13836)
  ...
antopalidi pushed a commit to openpoke/decidim that referenced this pull request Feb 12, 2025
andreslucena pushed a commit that referenced this pull request Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: core release: v0.28 Issues or PRs that need to be tackled for v0.28 release: v0.29 Issues or PRs that need to be tackled for v0.29 type: fix PRs that implement a fix for a bug

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

Single attachment with title does work

2 participants