Allow Attachment to answer to can_participate? based on it's attached model#15950
Conversation
📝 WalkthroughWalkthroughAdds a delegation so Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@decidim-core/app/models/decidim/attachment.rb`:
- Line 23: The current delegate line "delegate :can_participate?, to:
:attached_to" can raise NoMethodError for polymorphic targets that don't
implement can_participate?; replace this with an explicit instance method (e.g.,
def can_participate?) that mirrors the file's defensive pattern used by
organization and context: check attached_to.present? and use
attached_to.respond_to?(:can_participate?) ? attached_to.can_participate? : true
so attachments default to allowing participation when the target lacks the
method.
|
Wouldn't be best to use |
I think that, in the notifications (where we are having this problem), the models that it can be attached to are either components or participatory spaces (both have this method as done in https://github.com/decidim/decidim/pull/15830/files) An example in one of our instances: irb(main):005> Decidim::Attachment.pluck(:attached_to_type).uniq
=> ["Decidim::Assembly", "Decidim::Accountability::Result", "Decidim::Meetings::Meeting", "Decidim::ParticipatoryProcess", "Decidim::Blogs::Post"]Edit: The models shown do this with the included do
belongs_to :component, foreign_key: "decidim_component_id", class_name: "Decidim::Component", touch: true
delegate :organization, to: :component, allow_nil: true
delegate :participatory_space, :can_participate_in_space?, to: :component, allow_nil: true
alias_method :can_participate?, :can_participate_in_space?
end |
|
Well, I've seen that the reported bug has been delivered already in the 0.30.5 and 0.31.1 :_) |
|
@davidbeig is this PR ready for review? |
alecslupu
left a comment
There was a problem hiding this comment.
👍 - Merging without associated spec


🎩 What? Why?
Please describe your pull request.
The model attachment is missing a
can_participate?function. With this PR we are delegating that to the model at theattached_tofield.📌 Related Issues
Link your PR to an issue
Testing
Describe the best way to test or validate your PR.
You can reproduce the same steps as in the related issue.
Also, you can test in the console if an attachment now answers to this function.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.