attachments: fix opening the delete link directly
When cliking on the "Delete attachment" link, and opening the URL in a new tab, the `DELETE /attachements/:id` will become `GET /attachments/:id` – which will cause the `show` action to be routed with an html format (instead of JS). In that case, we don't want to throw an error at the user face. Instead simply re-render the dossier page (if any). Fix a long-standing error in Sentry.
This commit is contained in:
parent
0077ff4b75
commit
b748e9773f
2 changed files with 11 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue