2019-05-21 14:21:55 +02:00
|
|
|
class AttachmentsController < ApplicationController
|
|
|
|
before_action :authenticate_logged_user!
|
|
|
|
include ActiveStorage::SetBlob
|
|
|
|
|
|
|
|
def show
|
|
|
|
@attachment = @blob.attachments.find(params[:id])
|
2022-11-09 12:33:20 +01:00
|
|
|
|
|
|
|
@user_can_edit = cast_bool(params[:user_can_edit])
|
2023-09-20 16:52:30 +02:00
|
|
|
@direct_upload = cast_bool(params[:direct_upload])
|
2022-12-08 00:15:05 +01:00
|
|
|
@view_as = params[:view_as]&.to_sym
|
2022-11-09 12:33:20 +01:00
|
|
|
@auto_attach_url = params[:auto_attach_url]
|
2020-04-08 17:53:04 +02:00
|
|
|
|
|
|
|
respond_to do |format|
|
2022-05-06 12:25:58 +02:00
|
|
|
format.turbo_stream
|
2020-04-08 18:07:28 +02:00
|
|
|
format.html { redirect_back(fallback_location: root_url) }
|
2020-04-08 17:53:04 +02:00
|
|
|
end
|
2019-05-21 14:21:55 +02:00
|
|
|
end
|
2019-05-29 12:05:28 +02:00
|
|
|
|
|
|
|
def destroy
|
2022-05-06 12:25:58 +02:00
|
|
|
@attachment = @blob.attachments.find(params[:id])
|
|
|
|
@attachment.purge_later
|
|
|
|
flash.notice = 'La pièce jointe a bien été supprimée.'
|
|
|
|
|
2024-07-11 17:33:52 +02:00
|
|
|
if params[:dossier_id]
|
|
|
|
@champ = find_champ
|
|
|
|
else
|
|
|
|
@attachment_options = attachment_options
|
|
|
|
end
|
2022-11-09 12:33:20 +01:00
|
|
|
|
2022-05-06 12:25:58 +02:00
|
|
|
respond_to do |format|
|
|
|
|
format.turbo_stream
|
|
|
|
format.html { redirect_back(fallback_location: root_url) }
|
|
|
|
end
|
2019-05-29 12:05:28 +02:00
|
|
|
end
|
2024-07-05 15:27:39 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_champ
|
|
|
|
dossier = policy_scope(Dossier).includes(:champs).find(params[:dossier_id])
|
|
|
|
dossier.champs.find_by(stable_id: params[:stable_id], row_id: params[:row_id])
|
|
|
|
end
|
2024-07-11 17:33:52 +02:00
|
|
|
|
|
|
|
def attachment_options
|
|
|
|
{
|
|
|
|
attached_file: @attachment.record.public_send(@attachment.name),
|
|
|
|
auto_attach_url: params[:auto_attach_url],
|
|
|
|
view_as: params[:view_as]&.to_sym
|
|
|
|
}
|
|
|
|
end
|
2019-05-21 14:21:55 +02:00
|
|
|
end
|