Commit 304d6a90 authored by Stan Hu's avatar Stan Hu Committed by Robert Speicher

Move API group deletion to Sidekiq

parent 3adb5bb4
---
title: Move API group deletion to Sidekiq
merge_request:
author:
type: changed
...@@ -492,6 +492,9 @@ Parameters: ...@@ -492,6 +492,9 @@ Parameters:
- `id` (required) - The ID or path of a user group - `id` (required) - The ID or path of a user group
This will queue a background job to delete all projects in the group. The
response will be a 202 Accepted if the user has authorization.
## Search for group ## Search for group
Get all groups that match your string in their name or path. Get all groups that match your string in their name or path.
......
...@@ -203,9 +203,10 @@ module API ...@@ -203,9 +203,10 @@ module API
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/46285') Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/46285')
destroy_conditionally!(group) do |group| destroy_conditionally!(group) do |group|
::Groups::DestroyService.new(group, current_user).execute ::Groups::DestroyService.new(group, current_user).async_execute
end end
status 204
accepted!
end end
desc 'Get a list of projects in this group.' do desc 'Get a list of projects in this group.' do
......
...@@ -155,8 +155,9 @@ module API ...@@ -155,8 +155,9 @@ module API
group = find_group!(params[:id]) group = find_group!(params[:id])
authorize! :admin_group, group authorize! :admin_group, group
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/46285') ::Groups::DestroyService.new(group, current_user).async_execute
present ::Groups::DestroyService.new(group, current_user).execute, with: Entities::GroupDetail, current_user: current_user
accepted!
end end
desc 'Get a list of projects in this group.' do desc 'Get a list of projects in this group.' do
......
...@@ -818,13 +818,16 @@ describe API::Groups do ...@@ -818,13 +818,16 @@ describe API::Groups do
describe "DELETE /groups/:id" do describe "DELETE /groups/:id" do
context "when authenticated as user" do context "when authenticated as user" do
it "removes group" do it "removes group" do
delete api("/groups/#{group1.id}", user1) Sidekiq::Testing.fake! do
expect { delete api("/groups/#{group1.id}", user1) }.to change(GroupDestroyWorker.jobs, :size).by(1)
end
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(202)
end end
it_behaves_like '412 response' do it_behaves_like '412 response' do
let(:request) { api("/groups/#{group1.id}", user1) } let(:request) { api("/groups/#{group1.id}", user1) }
let(:success_status) { 202 }
end end
it "does not remove a group if not an owner" do it "does not remove a group if not an owner" do
...@@ -853,7 +856,7 @@ describe API::Groups do ...@@ -853,7 +856,7 @@ describe API::Groups do
it "removes any existing group" do it "removes any existing group" do
delete api("/groups/#{group2.id}", admin) delete api("/groups/#{group2.id}", admin)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(202)
end end
it "does not remove a non existing group" do it "does not remove a non existing group" do
......
...@@ -607,9 +607,11 @@ describe API::V3::Groups do ...@@ -607,9 +607,11 @@ describe API::V3::Groups do
describe "DELETE /groups/:id" do describe "DELETE /groups/:id" do
context "when authenticated as user" do context "when authenticated as user" do
it "removes group" do it "removes group" do
delete v3_api("/groups/#{group1.id}", user1) Sidekiq::Testing.fake! do
expect { delete v3_api("/groups/#{group1.id}", user1) }.to change(GroupDestroyWorker.jobs, :size).by(1)
end
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(202)
end end
it "does not remove a group if not an owner" do it "does not remove a group if not an owner" do
...@@ -638,7 +640,7 @@ describe API::V3::Groups do ...@@ -638,7 +640,7 @@ describe API::V3::Groups do
it "removes any existing group" do it "removes any existing group" do
delete v3_api("/groups/#{group2.id}", admin) delete v3_api("/groups/#{group2.id}", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(202)
end end
it "does not remove a non existing group" do it "does not remove a non existing group" do
......
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