diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 93f86f718..b187eda83 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -5,6 +5,11 @@ class AttachmentsController < ApplicationController def show @attachment = @blob.attachments.find(params[:id]) @user_can_upload = params[:user_can_upload] + + respond_to do |format| + format.js + format.html { redirect_back(fallback_location: @attachment.record&.dossier || root_path) } + end end def destroy diff --git a/spec/controllers/attachments_controller_spec.rb b/spec/controllers/attachments_controller_spec.rb index 0f1d71184..e460ca34b 100644 --- a/spec/controllers/attachments_controller_spec.rb +++ b/spec/controllers/attachments_controller_spec.rb @@ -28,6 +28,12 @@ describe AttachmentsController, type: :controller do end end + context 'when the user opens the delete link in a new tab' do + let(:format) { :html } + + it { is_expected.to have_http_status(302) } + it { is_expected.to redirect_to(dossier_path(dossier)) } + end end context 'when not authenticated' do