Commit 53ad352d authored by Sean McGivern's avatar Sean McGivern

Merge branch 'services-usage-7' into 'master'

Add DestroyService for deleting GPG keys and use it when admin deletes GPG key of a user via API

See merge request gitlab-org/gitlab!34935
parents 4d460c88 4c70a7b5
# frozen_string_literal: true
module GpgKeys
class DestroyService < Keys::BaseService
def execute(key)
key.destroy
end
end
end
---
title: Add DestroyService for GPG keys and use for deleting GPG keys via API
merge_request: 34935
author: Rajendra Kadam
type: fixed
...@@ -374,9 +374,10 @@ module API ...@@ -374,9 +374,10 @@ module API
key = user.gpg_keys.find_by(id: params[:key_id]) key = user.gpg_keys.find_by(id: params[:key_id])
not_found!('GPG Key') unless key not_found!('GPG Key') unless key
key.destroy destroy_conditionally!(key) do |key|
destroy_service = ::GpgKeys::DestroyService.new(current_user)
no_content! destroy_service.execute(key)
end
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
# frozen_string_literal: true
require 'spec_helper'
describe GpgKeys::DestroyService do
let(:user) { create(:user) }
subject { described_class.new(user) }
it 'destroys the GPG key' do
gpg_key = create(:gpg_key)
expect { subject.execute(gpg_key) }.to change(GpgKey, :count).by(-1)
end
end
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