refactor(attachment): remove replace feature
This commit is contained in:
parent
b8296c6d4d
commit
7ae6efe776
5 changed files with 3 additions and 23 deletions
|
@ -60,7 +60,7 @@ class Attachment::EditComponent < ApplicationComponent
|
||||||
end
|
end
|
||||||
|
|
||||||
def auto_attach_url
|
def auto_attach_url
|
||||||
helpers.auto_attach_url(form.object, replace_attachment_id: persisted? ? attachment_id : nil)
|
helpers.auto_attach_url(form.object)
|
||||||
end
|
end
|
||||||
|
|
||||||
def input_id(given_id)
|
def input_id(given_id)
|
||||||
|
@ -95,14 +95,6 @@ class Attachment::EditComponent < ApplicationComponent
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def replace_button_options
|
|
||||||
{
|
|
||||||
type: 'button',
|
|
||||||
class: 'button small',
|
|
||||||
data: { toggle_target: ".#{attachment_input_class}" }
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def file_size_validator
|
def file_size_validator
|
||||||
@attached_file.record
|
@attached_file.record
|
||||||
._validators[file_field_name.to_sym]
|
._validators[file_field_name.to_sym]
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
- if user_can_destroy?
|
- if user_can_destroy?
|
||||||
.attachment-action{ "data-turbo": "true" }
|
.attachment-action{ "data-turbo": "true" }
|
||||||
= link_to('Supprimer', attachment_path, **remove_button_options)
|
= link_to('Supprimer', attachment_path, **remove_button_options)
|
||||||
.attachment-action
|
|
||||||
= button_tag('Remplacer', **replace_button_options)
|
|
||||||
|
|
||||||
.attachment-error.hidden
|
.attachment-error.hidden
|
||||||
.attachment-error-message
|
.attachment-error-message
|
||||||
|
|
|
@ -14,8 +14,6 @@ class Champs::PieceJustificativeController < ApplicationController
|
||||||
def attach_piece_justificative
|
def attach_piece_justificative
|
||||||
@champ = policy_scope(Champ).find(params[:champ_id])
|
@champ = policy_scope(Champ).find(params[:champ_id])
|
||||||
|
|
||||||
purge_replaced_attachment
|
|
||||||
|
|
||||||
@champ.piece_justificative_file.attach(params[:blob_signed_id])
|
@champ.piece_justificative_file.attach(params[:blob_signed_id])
|
||||||
save_succeed = @champ.save
|
save_succeed = @champ.save
|
||||||
@champ.dossier.update(last_champ_updated_at: Time.zone.now.utc) if save_succeed
|
@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
|
rescue ActiveRecord::StaleObjectError
|
||||||
attach_piece_justificative
|
attach_piece_justificative
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -7,9 +7,9 @@ module ChampHelper
|
||||||
simple_format(auto_linked_text, {}, sanitize: false)
|
simple_format(auto_linked_text, {}, sanitize: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def auto_attach_url(object, url_options = {})
|
def auto_attach_url(object)
|
||||||
if object.is_a?(Champ)
|
if object.is_a?(Champ)
|
||||||
champs_piece_justificative_url(object.id, url_options)
|
champs_piece_justificative_url(object.id)
|
||||||
elsif object.is_a?(TypeDeChamp)
|
elsif object.is_a?(TypeDeChamp)
|
||||||
piece_justificative_template_admin_procedure_type_de_champ_url(stable_id: object.stable_id, procedure_id: object.procedure.id)
|
piece_justificative_template_admin_procedure_type_de_champ_url(stable_id: object.stable_id, procedure_id: object.procedure.id)
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,7 +30,6 @@ describe 'shared/attachment/_update.html.haml', type: :view do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not render action buttons' do
|
it 'does not render action buttons' do
|
||||||
expect(subject).not_to have_link('Remplacer')
|
|
||||||
expect(subject).not_to have_link('Supprimer')
|
expect(subject).not_to have_link('Supprimer')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue