From 0a114270af15a97edc6d3cd0910e35e70757c90c Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 17 Nov 2022 19:18:58 +0100 Subject: [PATCH] refactor(attachment): update Attachment::EditComponent everywhere --- app/assets/stylesheets/message.scss | 4 -- app/components/attachment/edit_component.rb | 46 +++++++++++-------- .../edit_component/edit_component.html.haml | 5 +- .../attachment/multiple_component.rb | 4 +- .../multiple_component.html.haml | 4 +- .../show_component/show_component.html.haml | 2 +- .../message_component.html.haml | 2 +- app/controllers/attachments_controller.rb | 1 + app/helpers/form_tag_helper.rb | 39 ++++++++++++++++ .../_informations.html.haml | 4 +- .../procedures/_informations.html.haml | 6 +-- .../administrateurs/procedures/edit.html.haml | 4 +- .../administrateurs/procedures/new.html.haml | 3 +- app/views/attachments/show.turbo_stream.haml | 2 +- app/views/experts/avis/instruction.html.haml | 4 +- .../experts/avis/shared/avis/_form.html.haml | 2 +- app/views/experts/shared/avis/_form.html.haml | 4 +- .../instructeurs/avis/instruction.html.haml | 2 +- .../instructeurs/shared/avis/_form.html.haml | 4 +- app/views/root/patron.html.haml | 14 +++++- .../shared/dossiers/messages/_form.html.haml | 4 +- .../attachment/_update.html.haml_spec.rb | 14 ++---- 22 files changed, 109 insertions(+), 65 deletions(-) create mode 100644 app/helpers/form_tag_helper.rb diff --git a/app/assets/stylesheets/message.scss b/app/assets/stylesheets/message.scss index 488e3f516..95960b192 100644 --- a/app/assets/stylesheets/message.scss +++ b/app/assets/stylesheets/message.scss @@ -29,10 +29,6 @@ float: right; } - .attachment-link { - margin-top: $default-spacer; - } - .message-answer-button { margin-left: auto; } diff --git a/app/components/attachment/edit_component.rb b/app/components/attachment/edit_component.rb index e38ebe5a2..01421c21a 100644 --- a/app/components/attachment/edit_component.rb +++ b/app/components/attachment/edit_component.rb @@ -2,15 +2,22 @@ class Attachment::EditComponent < ApplicationComponent attr_reader :champ attr_reader :attachment + attr_reader :user_can_download + alias user_can_download? user_can_download attr_reader :as_multiple alias as_multiple? as_multiple EXTENSIONS_ORDER = ['jpeg', 'png', 'pdf', 'zip'].freeze - def initialize(champ: nil, auto_attach_url: nil, attached_file:, direct_upload: true, id: nil, index: 0, as_multiple: false, **kwargs) - @champ = champ - @auto_attach_url = auto_attach_url + def initialize(champ: nil, auto_attach_url: nil, field_name: nil, attached_file:, direct_upload: true, id: nil, index: 0, as_multiple: false, user_can_download: false, **kwargs) + @as_multiple = as_multiple @attached_file = attached_file + @auto_attach_url = auto_attach_url + @champ = champ + @direct_upload = direct_upload + @id = id + @index = index + @user_can_download = user_can_download # attachment passed by kwarg because we don't want a default (nil) value. @attachment = if kwargs.key?(:attachment) @@ -21,16 +28,7 @@ class Attachment::EditComponent < ApplicationComponent fail ArgumentError, "You must pass an `attachment` kwarg when not using as single attachment like in #{attached_file.name}. Set it to nil for a new attachment." end - fail ArgumentError, "Unknown kwarg #{kwargs.keys.join(', ')}" unless kwargs.empty? - - @direct_upload = direct_upload - @id = id - @index = index - @as_multiple = as_multiple - end - - def object_name - @object.class.name.underscore + verify_initialization!(kwargs) end def first? @@ -100,11 +98,15 @@ class Attachment::EditComponent < ApplicationComponent if champ.present? auto_attach_url else - attachment_path(user_can_edit: true, auto_attach_url: @auto_attach_url) + attachment_path(user_can_edit: true, user_can_download: @user_can_download, auto_attach_url: @auto_attach_url) end end - def file_field_name + def field_name + helpers.field_name(ActiveModel::Naming.param_key(@attached_file.record), attribute_name) + end + + def attribute_name @attached_file.name end @@ -151,7 +153,7 @@ class Attachment::EditComponent < ApplicationComponent return "#{champ.input_id}_#{attachment_id}" end - file_field_name + helpers.field_id(@attached_file.record, attribute_name) end def auto_attach_url @@ -159,18 +161,18 @@ class Attachment::EditComponent < ApplicationComponent return helpers.auto_attach_url(@champ) if @champ.present? - fail ArgumentError, "You must pass `auto_attach_url` when not using attachment for a Champ" + nil end def file_size_validator @attached_file.record - ._validators[file_field_name.to_sym] + ._validators[attribute_name.to_sym] .find { |validator| validator.class == ActiveStorageValidations::SizeValidator } end def content_type_validator @attached_file.record - ._validators[file_field_name.to_sym] + ._validators[attribute_name.to_sym] .find { |validator| validator.class == ActiveStorageValidations::ContentTypeValidator } end @@ -204,12 +206,16 @@ class Attachment::EditComponent < ApplicationComponent return false end + def verify_initialization!(kwargs) + fail ArgumentError, "Unknown kwarg #{kwargs.keys.join(', ')}" unless kwargs.empty? + end + def track_issue_with_missing_validators Sentry.capture_message( "Strange case of missing validator", extra: { champ: champ, - file_field_name: file_field_name, + field_name: field_name, attachment_id: attachment_id } ) diff --git a/app/components/attachment/edit_component/edit_component.html.haml b/app/components/attachment/edit_component/edit_component.html.haml index 344c617a8..db489e64a 100644 --- a/app/components/attachment/edit_component/edit_component.html.haml +++ b/app/components/attachment/edit_component/edit_component.html.haml @@ -5,7 +5,8 @@ = link_to('Supprimer', destroy_attachment_path, **remove_button_options, class: "fr-btn fr-btn--tertiary fr-btn--sm fr-icon-delete-line", title: "Supprimer le fichier #{attachment.filename}") .fr-py-1v - %span.attachment-filename= attachment.filename.to_s + = link_to_if(user_can_download?, attachment.filename.to_s, attachment.url, class: "attachment-filename", download: "") do + %span.attachment-filename= attachment.filename.to_s - if in_progress? %p.fr-badge.fr-badge--info.fr-badge--sm.fr-badge--no-icon.fr-ml-1w = progress_bar_label @@ -23,7 +24,7 @@ - if !as_multiple? - = file_field(champ, file_field_name, **file_field_options) + = file_field(champ, field_name, **file_field_options) - if in_progress? %div{ data: poll_controller_options } diff --git a/app/components/attachment/multiple_component.rb b/app/components/attachment/multiple_component.rb index cd660684f..75caae41c 100644 --- a/app/components/attachment/multiple_component.rb +++ b/app/components/attachment/multiple_component.rb @@ -4,18 +4,16 @@ class Attachment::MultipleComponent < ApplicationComponent attr_reader :form attr_reader :attached_file - attr_reader :direct_upload attr_reader :id attr_reader :user_can_destroy attr_reader :max delegate :count, :empty?, to: :attachments, prefix: true - def initialize(form:, attached_file:, user_can_destroy: false, direct_upload: true, id: nil, max: nil) + def initialize(form:, attached_file:, user_can_destroy: false, id: nil, max: nil) @form = form @attached_file = attached_file @user_can_destroy = user_can_destroy - @direct_upload = direct_upload @id = id @max = max || 10 diff --git a/app/components/attachment/multiple_component/multiple_component.html.haml b/app/components/attachment/multiple_component/multiple_component.html.haml index 8e4083002..7b493ae28 100644 --- a/app/components/attachment/multiple_component/multiple_component.html.haml +++ b/app/components/attachment/multiple_component/multiple_component.html.haml @@ -3,10 +3,10 @@ - each_attachment do |attachment, index| %div{ id: dom_id(attachment) } - = render Attachment::EditComponent.new(champ:, attached_file:, attachment:, direct_upload:, id:, index:, as_multiple: true) + = render Attachment::EditComponent.new(champ:, attached_file:, attachment:, id:, index:, as_multiple: true) %div{ id: empty_component_id, class: class_names("hidden": !can_attach_next?) } - = render Attachment::EditComponent.new(champ:, attached_file:, attachment: nil, direct_upload:, id:, index: attachments_count) + = render Attachment::EditComponent.new(champ:, attached_file:, attachment: nil, id:, index: attachments_count) // single poll and refresh message for all attachments - if in_progress? diff --git a/app/components/attachment/show_component/show_component.html.haml b/app/components/attachment/show_component/show_component.html.haml index 2c3629700..8ce2193cf 100644 --- a/app/components/attachment/show_component/show_component.html.haml +++ b/app/components/attachment/show_component/show_component.html.haml @@ -1,4 +1,4 @@ -.attachment-link{ id: dom_id(attachment, :show), class: class_names("attachment-error": error?, "fr-mb-2w": !should_display_link?) } +%div{ id: dom_id(attachment, :show), class: class_names("attachment-error": error?, "fr-mb-2w": !should_display_link?) } - if should_display_link? = render Dsfr::DownloadComponent.new(attachment: attachment) do |c| - if !attachment.virus_scanner.started? diff --git a/app/components/dossiers/message_component/message_component.html.haml b/app/components/dossiers/message_component/message_component.html.haml index 980ef7398..176b74018 100644 --- a/app/components/dossiers/message_component/message_component.html.haml +++ b/app/components/dossiers/message_component/message_component.html.haml @@ -17,7 +17,7 @@ = t('.delete_button') - if commentaire.piece_jointe.attached? - .attachment-link + .fr-ml-2w = render Attachment::ShowComponent.new(attachment: commentaire.piece_jointe.attachment) - if show_reply_button? diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index d2ba09746..d5477c2cf 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -6,6 +6,7 @@ class AttachmentsController < ApplicationController @attachment = @blob.attachments.find(params[:id]) @user_can_edit = cast_bool(params[:user_can_edit]) + @user_can_download = cast_bool(params[:user_can_download]) @auto_attach_url = params[:auto_attach_url] respond_to do |format| diff --git a/app/helpers/form_tag_helper.rb b/app/helpers/form_tag_helper.rb new file mode 100644 index 000000000..68971b454 --- /dev/null +++ b/app/helpers/form_tag_helper.rb @@ -0,0 +1,39 @@ +module FormTagHelper + # from Rails 7 ActionView::Helpers::FormTagHelper + # https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-field_id + # Should be removed when we upgrade to Rails 7 + def field_id(object_name, method_name, *suffixes, index: nil, namespace: nil) + if object_name.respond_to?(:model_name) + object_name = object_name.model_name.singular + end + + sanitized_object_name = object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").delete_suffix("_") + + sanitized_method_name = method_name.to_s.delete_suffix("?") + + [ + namespace, + sanitized_object_name.presence, + (index unless sanitized_object_name.empty?), + sanitized_method_name, + *suffixes + ].tap(&:compact!).join("_") + end + + # from Rails 7 ActionView::Helpers::FormTagHelper + # https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-field_name + # Should be removed when we upgrade to Rails 7 + def field_name(object_name, method_name, *method_names, multiple: false, index: nil) + names = method_names.map! { |name| "[#{name}]" }.join + + # a little duplication to construct fewer strings + case + when object_name.blank? + "#{method_name}#{names}#{multiple ? "[]" : ""}" + when index + "#{object_name}[#{index}][#{method_name}]#{names}#{multiple ? "[]" : ""}" + else + "#{object_name}[#{method_name}]#{names}#{multiple ? "[]" : ""}" + end + end +end diff --git a/app/views/administrateurs/attestation_templates/_informations.html.haml b/app/views/administrateurs/attestation_templates/_informations.html.haml index fe30f13fd..1c85197ca 100644 --- a/app/views/administrateurs/attestation_templates/_informations.html.haml +++ b/app/views/administrateurs/attestation_templates/_informations.html.haml @@ -25,7 +25,7 @@ = tag[:description] %h3.header-subsection Logo de l'attestation -= render Attachment::EditComponent.new(form: f, attached_file: @attestation_template.logo, direct_upload: false, user_can_destroy: true) += render Attachment::EditComponent.new(attached_file: @attestation_template.logo, direct_upload: false) %p.notice Formats acceptés : JPG / JPEG / PNG. @@ -33,7 +33,7 @@ Dimensions conseillées : au minimum 500 px de largeur ou de hauteur, poids maximum : 0,5 Mo. %h3.header-subsection Tampon de l'attestation -= render Attachment::EditComponent.new(form: f, attached_file: @attestation_template.signature, direct_upload: false, user_can_destroy: true) += render Attachment::EditComponent.new(attached_file: @attestation_template.signature, direct_upload: false) %p.notice Formats acceptés : JPG / JPEG / PNG. diff --git a/app/views/administrateurs/procedures/_informations.html.haml b/app/views/administrateurs/procedures/_informations.html.haml index bdcdbd6db..e0990f3e2 100644 --- a/app/views/administrateurs/procedures/_informations.html.haml +++ b/app/views/administrateurs/procedures/_informations.html.haml @@ -14,7 +14,7 @@ = f.text_area :description, rows: '6', placeholder: 'Description de la démarche, destinataires, etc. ', class: 'form-control' %h3.header-subsection Logo de la démarche -= render Attachment::EditComponent.new(form: f, attached_file: @procedure.logo, direct_upload: true, user_can_destroy: true) += render Attachment::EditComponent.new(attached_file: @procedure.logo, user_can_download: true) %h3.header-subsection Conservation des données = f.label :duree_conservation_dossiers_dans_ds do @@ -52,7 +52,7 @@ = f.text_field :cadre_juridique, class: 'form-control', placeholder: 'https://www.legifrance.gouv.fr/' = f.label :deliberation, 'Importer le texte' -= render Attachment::EditComponent.new(form: f, attached_file: @procedure.deliberation, user_can_destroy: true) += render Attachment::EditComponent.new(attached_file: @procedure.deliberation, user_can_download: true) %h3.header-subsection RGPD @@ -81,7 +81,7 @@ = f.label :notice, 'Notice' %p.notice Formats acceptés : .doc, .odt, .pdf, .ppt, .pptx -= render Attachment::EditComponent.new(form: f, attached_file: @procedure.notice, user_can_destroy: true) += render Attachment::EditComponent.new(attached_file: @procedure.notice, user_can_download: true) - if !@procedure.locked? %h3.header-subsection À qui s’adresse ma démarche ? diff --git a/app/views/administrateurs/procedures/edit.html.haml b/app/views/administrateurs/procedures/edit.html.haml index 81d97a080..e8ff47733 100644 --- a/app/views/administrateurs/procedures/edit.html.haml +++ b/app/views/administrateurs/procedures/edit.html.haml @@ -8,8 +8,8 @@ .procedure-form__columns.container = form_for @procedure, url: url_for({ controller: 'administrateurs/procedures', action: :update, id: @procedure.id }), - multipart: true, - html: { class: 'form procedure-form__column--form' } do |f| + html: { class: 'form procedure-form__column--form', + multipart: true } do |f| %h1.page-title Description diff --git a/app/views/administrateurs/procedures/new.html.haml b/app/views/administrateurs/procedures/new.html.haml index ba0586866..68daee102 100644 --- a/app/views/administrateurs/procedures/new.html.haml +++ b/app/views/administrateurs/procedures/new.html.haml @@ -8,8 +8,7 @@ .procedure-form__columns.container = form_for @procedure, url: url_for({ controller: 'administrateurs/procedures', action: :create, id: @procedure.id }), - multipart: true, - html: { class: 'form procedure-form__column--form' } do |f| + html: { class: 'form procedure-form__column--form', multipart: true } do |f| %h1.page-title Nouvelle démarche diff --git a/app/views/attachments/show.turbo_stream.haml b/app/views/attachments/show.turbo_stream.haml index 2ca8330a4..fd0b23580 100644 --- a/app/views/attachments/show.turbo_stream.haml +++ b/app/views/attachments/show.turbo_stream.haml @@ -1,5 +1,5 @@ = turbo_stream.replace dom_id(@attachment, :edit) do - if @user_can_edit - = render Attachment::EditComponent.new(attachment: @attachment, attached_file: @attachment.record.public_send(@attachment.name), auto_attach_url: @auto_attach_url) + = render Attachment::EditComponent.new(attachment: @attachment, attached_file: @attachment.record.public_send(@attachment.name), auto_attach_url: @auto_attach_url, user_can_download: @user_can_download) - else = render Attachment::ShowComponent.new(attachment: @attachment) diff --git a/app/views/experts/avis/instruction.html.haml b/app/views/experts/avis/instruction.html.haml index b566e9c2c..b1604da53 100644 --- a/app/views/experts/avis/instruction.html.haml +++ b/app/views/experts/avis/instruction.html.haml @@ -15,9 +15,9 @@ = render Attachment::ShowComponent.new(attachment: @avis.introduction_file.attachment) %br/ - = form_for @avis, url: expert_avis_path(@avis.procedure, @avis), html: { class: 'form', data: { controller: 'persisted-form', persisted_form_key_value: dom_id(@avis) } } do |f| + = form_for @avis, url: expert_avis_path(@avis.procedure, @avis), html: { class: 'form', data: { controller: 'persisted-form', persisted_form_key_value: dom_id(@avis) }, multipart: true } do |f| = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true - = render Attachment::EditComponent.new(form: f, attached_file: @avis.piece_justificative_file, user_can_destroy: true) + = render Attachment::EditComponent.new(attached_file: @avis.piece_justificative_file, user_can_download: true) .flex.justify-between.align-baseline %p.confidentiel.flex diff --git a/app/views/experts/avis/shared/avis/_form.html.haml b/app/views/experts/avis/shared/avis/_form.html.haml index caaea9dbc..ec832f257 100644 --- a/app/views/experts/avis/shared/avis/_form.html.haml +++ b/app/views/experts/avis/shared/avis/_form.html.haml @@ -7,7 +7,7 @@ = f.text_area :introduction, rows: 3, value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true %p.tab-title Ajouter une pièce jointe .form-group - = render Attachment::EditComponent.new(form: f, attached_file: avis.introduction_file, user_can_destroy: true) + = render Attachment::EditComponent.new(attached_file: avis.introduction_file) - if linked_dossiers.present? = f.check_box :invite_linked_dossiers, {}, true, false diff --git a/app/views/experts/shared/avis/_form.html.haml b/app/views/experts/shared/avis/_form.html.haml index 2a39e59aa..1d6b70ab5 100644 --- a/app/views/experts/shared/avis/_form.html.haml +++ b/app/views/experts/shared/avis/_form.html.haml @@ -3,7 +3,7 @@ %h1.tab-title Inviter des personnes à donner leur avis %p.avis-notice Les invités pourront consulter le dossier, donner un avis et contribuer au fil de messagerie. Ils ne pourront pas modifier le dossier. - = form_for avis, url: url, html: { class: 'form', data: { controller: 'persisted-form', persisted_form_key_value: dom_id(@avis.dossier, :avis_by_expert) } } do |f| + = form_for avis, url: url, html: { class: 'form', multipart: true, data: { controller: 'persisted-form', persisted_form_key_value: dom_id(@avis.dossier, :avis_by_expert) } } do |f| = hidden_field_tag 'avis[emails]', nil = react_component("ComboMultiple", options: [], selected: [], disabled: [], @@ -14,7 +14,7 @@ = f.text_area :introduction, rows: 3, value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true %p.tab-title Ajouter une pièce jointe .form-group - = render Attachment::EditComponent.new(form: f, attached_file: avis.introduction_file, user_can_destroy: true) + = render Attachment::EditComponent.new(attached_file: avis.introduction_file) - if linked_dossiers.present? = f.check_box :invite_linked_dossiers, {}, true, false diff --git a/app/views/instructeurs/avis/instruction.html.haml b/app/views/instructeurs/avis/instruction.html.haml index e1ced5eec..a48ecb92e 100644 --- a/app/views/instructeurs/avis/instruction.html.haml +++ b/app/views/instructeurs/avis/instruction.html.haml @@ -17,7 +17,7 @@ = form_for @avis, url: instructeur_avis_path(@avis.procedure, @avis), html: { class: 'form' } do |f| = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true - = render Attachment::EditComponent.new(object: f.object, attached_file: @avis.piece_justificative_file, user_can_destroy: true) + = render Attachment::EditComponent.new(attached_file: @avis.piece_justificative_file) .flex.justify-between.align-baseline %p.confidentiel.flex diff --git a/app/views/instructeurs/shared/avis/_form.html.haml b/app/views/instructeurs/shared/avis/_form.html.haml index 70ebe0a24..90248d0f6 100644 --- a/app/views/instructeurs/shared/avis/_form.html.haml +++ b/app/views/instructeurs/shared/avis/_form.html.haml @@ -8,7 +8,7 @@ %p#avis-emails-description.avis-notice Entrez les adresses email des experts à qui vous souhaitez demander un avis - = form_for avis, url: url, html: { class: 'form', data: { controller: 'persisted-form', persisted_form_key_value: dom_id(@dossier, :avis_by_instructeur) } } do |f| + = form_for avis, url: url, html: { class: 'form', multipart: true, data: { controller: 'persisted-form', persisted_form_key_value: dom_id(@dossier, :avis_by_instructeur) } } do |f| = hidden_field_tag 'avis[emails]', nil = react_component("ComboMultiple", options: @dossier.procedure.experts_require_administrateur_invitation ? @experts_emails : [], @@ -21,7 +21,7 @@ = f.text_area :introduction, rows: 3, value: avis.introduction || 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true %p.tab-title Ajouter une pièce jointe .form-group - = render Attachment::EditComponent.new(object: f.object, attached_file: avis.introduction_file, user_can_destroy: true) + = render Attachment::EditComponent.new(attached_file: avis.introduction_file) - if linked_dossiers.present? = f.check_box :invite_linked_dossiers, {}, true, false diff --git a/app/views/root/patron.html.haml b/app/views/root/patron.html.haml index c30a2f4db..fab497799 100644 --- a/app/views/root/patron.html.haml +++ b/app/views/root/patron.html.haml @@ -355,6 +355,7 @@ - champ = @dossier.champs_public.first - tdc = @dossier.champs_public.find { _1.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }.type_de_champ + - avis = Avis.new - if attachment = ActiveStorage::Attachment.last - attachment.update(created_at: 1.second.ago) @@ -378,9 +379,18 @@ - attachment.blob.metadata[:virus_scan_result] = ActiveStorage::VirusScanner::INFECTED = render Attachment::EditComponent.new(champ:, attached_file: Champ.new.piece_justificative_file, attachment:) - %h3.fr-mt-4w New attachment not on Champ + %h3.fr-mt-4w New attachment on TypeDeChamp = render Attachment::EditComponent.new(auto_attach_url: "/some-auto-attach-path", attached_file: tdc.piece_justificative_template, attachment: nil) - %h3.fr-mt-4w Existing attachment not on Champ + %h3.fr-mt-4w Existing attachment on TypeDeChamp = render Attachment::EditComponent.new(auto_attach_url: "/some-auto-attach-path", attached_file: tdc.piece_justificative_template, attachment: attachment.reload) + %h3.fr-mt-4w Existing attachment on TypeDeChamp can download + = render Attachment::EditComponent.new(auto_attach_url: "/some-auto-attach-path", attached_file: tdc.piece_justificative_template, attachment: attachment.reload, user_can_download: true) + + %h3.fr-mt-4w New attachment on generic object + = render Attachment::EditComponent.new(attached_file: avis.introduction_file) + + %h3.fr-mt-4w Existing attachment on generic object, can download + = render Attachment::EditComponent.new(attached_file: avis.introduction_file, attachment: attachment.reload, user_can_download: true) + diff --git a/app/views/shared/dossiers/messages/_form.html.haml b/app/views/shared/dossiers/messages/_form.html.haml index a97c1193f..beac4ec37 100644 --- a/app/views/shared/dossiers/messages/_form.html.haml +++ b/app/views/shared/dossiers/messages/_form.html.haml @@ -1,4 +1,4 @@ -= form_for(commentaire, url: form_url, html: { class: 'form', data: { controller: 'persisted-form', persisted_form_key_value: @dossier.present? ? dom_id(@dossier) : dom_id(@procedure, :bulk_message) } }) do |f| += form_for(commentaire, url: form_url, html: { class: 'form', multipart: true, data: { controller: 'persisted-form', persisted_form_key_value: @dossier.present? ? dom_id(@dossier) : dom_id(@procedure, :bulk_message) } }) do |f| - dossier = commentaire.dossier - placeholder = t('views.shared.dossiers.messages.form.write_message_to_administration_placeholder') - if instructeur_signed_in? || administrateur_signed_in? || expert_signed_in? @@ -8,7 +8,7 @@ - disable_piece_jointe = defined?(disable_piece_jointe) ? disable_piece_jointe : false %div - if !disable_piece_jointe - = render Attachment::EditComponent.new(object: f.object, attached_file: commentaire.piece_jointe) + = render Attachment::EditComponent.new(attached_file: commentaire.piece_jointe) %div = f.submit t('views.shared.dossiers.messages.form.send_message'), class: 'button primary send', data: { disable: true } diff --git a/spec/views/shared/attachment/_update.html.haml_spec.rb b/spec/views/shared/attachment/_update.html.haml_spec.rb index cfeea90e7..791a7b2d4 100644 --- a/spec/views/shared/attachment/_update.html.haml_spec.rb +++ b/spec/views/shared/attachment/_update.html.haml_spec.rb @@ -5,9 +5,7 @@ describe 'shared/attachment/_update.html.haml', type: :view do let(:template) { nil } subject do - form_for(champ.dossier) do |form| - view.render Attachment::EditComponent.new(form: form, attached_file: attached_file, attachment: attached_file[0], user_can_destroy: true, direct_upload: true) - end + view.render Attachment::EditComponent.new(champ: champ, attached_file: attached_file, attachment: attached_file[0]) end context 'when there is no attached file' do @@ -52,13 +50,9 @@ describe 'shared/attachment/_update.html.haml', type: :view do context 'when the user cannot destroy the attachment' do subject do - form_for(champ.dossier) do |form| - render Attachment::EditComponent.new(form: form, - attached_file: attached_file, - attachment: attached_file[0], - user_can_destroy: user_can_destroy, - direct_upload: true) - end + render Attachment::EditComponent.new(champ: champ, + attached_file: attached_file, + attachment: attached_file[0]) end it 'hides the Delete button' do