Describe the bug
When reviewing #9361 I noticed that the survey answers cannot be shown in the admin panel if they have attachments in them.
Another problem is that these attachments do not have any title so even when it would be fixed, the link is invisible in this view.
To Reproduce
- Go to one of the surveys component
- Enable attachments (i.e. add file question) and answers + answers for unregistered users for that component
- Leave an answer with a valid attachment
- Go to the admin panel to see the answer (with the attachment) at
/admin/participatory_processes/{SLUG}/components/{ID}/manage/answer/123...
- See that the view is broken
Expected behavior
I would expect to be able to see the answer and download the file attached to the answer from the admin panel.
Screenshots
N/A
Stacktrace
ActionView::Template::Error (undefined method `link_to' for {:answer=>#<Decidim::Forms::Answer id: 5, body: nil, decidim_user_id: 2, decidim_questionnaire_id: 17, decidim_question_id: 617, created_at: "2022-06-14 16:06:49.349683000 +0000", updated_at: "2022-06-14 16:06:49.349683000 +0000", session_token: "1002124452832074857979725", ip_hash: "901765835486838166932599">}:Decidim::Forms::Admin::QuestionnaireAnswerPresenter):
41: <dl>
42: <% @participant.answers.each do |answer| %>
43: <dt><%= answer.question %></dt>
44: <dd><%= answer.body %></dd>
45: <% end %>
46: </dl>
47: </div>
/.../.rbenv/versions/3.0.2/lib/ruby/3.0.0/delegate.rb:91:in `method_missing'
/.../dev/rails/decidim/decidim-forms/app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb:57:in `block in pretty_attachment'
Extra data (please complete the following information):
- Device: (any)
- Device OS: (any)
- Browser: (any)
- Decidim Version: (any)
- Decidim installation: (any)
Additional context
The reason for this bug is that this method is trying to call view context methods that are not delegated to the view context:
|
content_tag :li do |
|
link_to(translated_attribute(attachment.title), attachment.url) + |
|
" " + |
|
content_tag(:small) do |
|
"#{attachment.file_type} #{number_to_human_size(attachment.file_size)}" |
|
end |
|
end |
So here:
|
delegate :content_tag, :safe_join, to: :view_context |
We should have:
delegate :content_tag, :link_to, :number_to_human_size, :safe_join, to: :view_context
And to fix the invisible link, we should replace this:
|
link_to(translated_attribute(attachment.title), attachment.url) + |
With something else, e.g. "Download attachment".
Describe the bug
When reviewing #9361 I noticed that the survey answers cannot be shown in the admin panel if they have attachments in them.
Another problem is that these attachments do not have any title so even when it would be fixed, the link is invisible in this view.
To Reproduce
/admin/participatory_processes/{SLUG}/components/{ID}/manage/answer/123...Expected behavior
I would expect to be able to see the answer and download the file attached to the answer from the admin panel.
Screenshots
N/A
Stacktrace
Extra data (please complete the following information):
Additional context
The reason for this bug is that this method is trying to call view context methods that are not delegated to the view context:
decidim/decidim-forms/app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb
Lines 56 to 62 in 441a461
So here:
decidim/decidim-forms/app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb
Line 10 in 441a461
We should have:
And to fix the invisible link, we should replace this:
decidim/decidim-forms/app/presenters/decidim/forms/admin/questionnaire_answer_presenter.rb
Line 57 in 441a461
With something else, e.g. "Download attachment".