From 7ae6efe7761adcf4b74aa28130f4521c3a27fbbf Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Sat, 29 Oct 2022 13:35:22 +0200 Subject: [PATCH] refactor(attachment): remove replace feature --- app/components/attachment/edit_component.rb | 10 +--------- .../attachment/edit_component/edit_component.html.haml | 2 -- .../champs/piece_justificative_controller.rb | 9 --------- app/helpers/champ_helper.rb | 4 ++-- spec/views/shared/attachment/_update.html.haml_spec.rb | 1 - 5 files changed, 3 insertions(+), 23 deletions(-) diff --git a/app/components/attachment/edit_component.rb b/app/components/attachment/edit_component.rb index 25ec4e2ea..e0e50d6cc 100644 --- a/app/components/attachment/edit_component.rb +++ b/app/components/attachment/edit_component.rb @@ -60,7 +60,7 @@ class Attachment::EditComponent < ApplicationComponent end def auto_attach_url - helpers.auto_attach_url(form.object, replace_attachment_id: persisted? ? attachment_id : nil) + helpers.auto_attach_url(form.object) end def input_id(given_id) @@ -95,14 +95,6 @@ class Attachment::EditComponent < ApplicationComponent } end - def replace_button_options - { - type: 'button', - class: 'button small', - data: { toggle_target: ".#{attachment_input_class}" } - } - end - def file_size_validator @attached_file.record ._validators[file_field_name.to_sym] diff --git a/app/components/attachment/edit_component/edit_component.html.haml b/app/components/attachment/edit_component/edit_component.html.haml index fc3e60515..f91503777 100644 --- a/app/components/attachment/edit_component/edit_component.html.haml +++ b/app/components/attachment/edit_component/edit_component.html.haml @@ -6,8 +6,6 @@ - if user_can_destroy? .attachment-action{ "data-turbo": "true" } = link_to('Supprimer', attachment_path, **remove_button_options) - .attachment-action - = button_tag('Remplacer', **replace_button_options) .attachment-error.hidden .attachment-error-message diff --git a/app/controllers/champs/piece_justificative_controller.rb b/app/controllers/champs/piece_justificative_controller.rb index 807bb70d2..b782f2ba8 100644 --- a/app/controllers/champs/piece_justificative_controller.rb +++ b/app/controllers/champs/piece_justificative_controller.rb @@ -14,8 +14,6 @@ class Champs::PieceJustificativeController < ApplicationController def attach_piece_justificative @champ = policy_scope(Champ).find(params[:champ_id]) - purge_replaced_attachment - @champ.piece_justificative_file.attach(params[:blob_signed_id]) save_succeed = @champ.save @champ.dossier.update(last_champ_updated_at: Time.zone.now.utc) if save_succeed @@ -27,11 +25,4 @@ class Champs::PieceJustificativeController < ApplicationController rescue ActiveRecord::StaleObjectError attach_piece_justificative end - - def purge_replaced_attachment - return if params[:replace_attachment_id].blank? - - attachment = @champ.piece_justificative_file.attachments.find { _1.id == params[:replace_attachment_id].to_i } - attachment&.purge_later - end end diff --git a/app/helpers/champ_helper.rb b/app/helpers/champ_helper.rb index d57caaf8b..2a66461bf 100644 --- a/app/helpers/champ_helper.rb +++ b/app/helpers/champ_helper.rb @@ -7,9 +7,9 @@ module ChampHelper simple_format(auto_linked_text, {}, sanitize: false) end - def auto_attach_url(object, url_options = {}) + def auto_attach_url(object) if object.is_a?(Champ) - champs_piece_justificative_url(object.id, url_options) + champs_piece_justificative_url(object.id) elsif object.is_a?(TypeDeChamp) piece_justificative_template_admin_procedure_type_de_champ_url(stable_id: object.stable_id, procedure_id: object.procedure.id) end diff --git a/spec/views/shared/attachment/_update.html.haml_spec.rb b/spec/views/shared/attachment/_update.html.haml_spec.rb index 10d689243..85ce3564f 100644 --- a/spec/views/shared/attachment/_update.html.haml_spec.rb +++ b/spec/views/shared/attachment/_update.html.haml_spec.rb @@ -30,7 +30,6 @@ describe 'shared/attachment/_update.html.haml', type: :view do end it 'does not render action buttons' do - expect(subject).not_to have_link('Remplacer') expect(subject).not_to have_link('Supprimer') end