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

fix: Trix field disable_attachments option unexpected behaviour #2462

Conversation

olivierbuffon
Copy link
Contributor

Description

This PR comes in order to fix a critical regression introduced by #2429 which changed

@attachments_disabled = args[:attachments_disabled] || false

by

@attachments_disabled = args[:attachments_disabled] || true
@attachments_disabled = false unless @attachment_key.present?

Unfortunately this created an unexpected behaviour making @attachments_disabled always defaulting to true. Here is why:

irb(main):001> args = {}
=> {}
irb(main):002> args[:attachments_disabled] = false
=> false
irb(main):003> @attachments_disabled = args[:attachments_disabled] || true
=> true

This has the side effect of breaking the attachment feature by always disabling it even when specifying an attachment key or manually set the attachments_disabled option to false.

This PR comes with a simple fix extracting the logic in a private method and validating if the boolean value is set to true or false.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Manual review steps

There's multiple ways to reproduce it:

  • Add a trix field with an attachment_key and try to add an attachment to the content
  • Add a trix field and explicitely set the attachments_disabled to true, the button to add an attachment will show up anyway

@github-actions github-actions bot added the Fix label Feb 7, 2024
Copy link

codeclimate bot commented Feb 7, 2024

Code Climate has analyzed commit 6f92d12 and detected 0 issues on this pull request.

View more on Code Climate.

@adrianthedev
Copy link
Collaborator

🤦‍♂️ Oh yeah... I didn't see that.

Thank you for the contribution and for digging into the problem @olivierbuffon.

@olivierbuffon
Copy link
Contributor Author

@adrianthedev No worries, my pleasure! Love the product by the way! Keep up the great job 👏!

@adrianthedev adrianthedev merged commit ebb4714 into avo-hq:main Feb 8, 2024
20 checks passed
@olivierbuffon olivierbuffon deleted the fix/trix_field_disable_attachments_unexpected_behaviour branch February 8, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants