Commit e0e5ee4e authored by Max Woolf's avatar Max Woolf Committed by Ash McKenzie

Return 404 when deleting non-existant SSH key

Currently when using the UI to delete an SSH key
via the credentials inventory, the HTTP status
code returned is always 201 regardless of the
outcome.

This commits adds a guard clause to render
a 404 Not Found error when attempting to
delete a non-existant SSH key.
parent aa5bde98
......@@ -17,15 +17,13 @@ module CredentialsInventoryActions
def destroy
key = KeysFinder.new({ users: users, key_type: 'ssh' }).find_by_id(params[:id])
alert = if key.present?
if Keys::DestroyService.new(current_user).execute(key)
notify_deleted_or_revoked_credential(key)
_('User key was successfully removed.')
else
_('Failed to remove user key.')
end
return render_404 if key.nil?
alert = if Keys::DestroyService.new(current_user).execute(key)
notify_deleted_or_revoked_credential(key)
_('User key was successfully removed.')
else
_('Cannot find user key.')
_('Failed to remove user key.')
end
redirect_to credentials_inventory_path(filter: 'ssh_keys'), status: :found, notice: alert
......
---
title: Return 404 when attempting to delete non-existent SSH key
merge_request: 46450
author:
type: fixed
......@@ -63,8 +63,7 @@ RSpec.shared_examples_for 'credentials inventory controller delete SSH key' do |
it 'renders a not found message' do
subject
expect(response).to redirect_to(credentials_path)
expect(flash[:notice]).to eql 'Cannot find user key.'
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
......
......@@ -4853,9 +4853,6 @@ msgstr ""
msgid "Cannot enable shared runners because parent group does not allow it"
msgstr ""
msgid "Cannot find user key."
msgstr ""
msgid "Cannot have multiple Jira imports running at the same time"
msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment