No user needed to cleanup namespaceless pending delete projects

Since this is a cleanup, ran by a post-deploy, there is no need to lookup the
admin to run the cleanup.
This commit is contained in:
Toon Claes 2017-05-09 22:16:52 +02:00
parent 0ad80cab40
commit 37a79409d4
4 changed files with 21 additions and 21 deletions

View file

@ -12,7 +12,7 @@ class NamespacelessProjectDestroyWorker
Sidekiq::Client.push_bulk('class' => self, 'queue' => sidekiq_options['queue'], 'args' => args_list)
end
def perform(project_id, user_id, params)
def perform(project_id)
begin
project = Project.unscoped.find(project_id)
rescue ActiveRecord::RecordNotFound
@ -20,9 +20,6 @@ class NamespacelessProjectDestroyWorker
end
return unless project.namespace_id.nil? # Reject doing anything for projects that *do* have a namespace
user = User.find(user_id)
return unless user.can?(:remove_project, project)
project.team.truncate
unlink_fork(project) if project.forked?

View file

@ -8,17 +8,14 @@ class CleanupNamespacelessPendingDeleteProjects < ActiveRecord::Migration
disable_ddl_transaction!
def up
admin = User.find_by(admin: true)
return unless admin
@offset = 0
loop do
ids = pending_delete_batch
break if ids.rows.count.zero?
break if ids.empty?
args = ids.map { |id| [id['id'], admin.id, {}] }
args = ids.map { |id| Array(id) }
NamespacelessProjectDestroyWorker.bulk_perform_async(args)
@ -33,7 +30,7 @@ class CleanupNamespacelessPendingDeleteProjects < ActiveRecord::Migration
private
def pending_delete_batch
connection.exec_query(find_batch)
connection.exec_query(find_batch).map{ |row| row['id'] }
end
BATCH_SIZE = 5000

View file

@ -10,13 +10,21 @@ describe CleanupNamespacelessPendingDeleteProjects do
describe '#up' do
it 'only cleans up pending delete projects' do
admin = create(:admin)
create(:empty_project)
create(:empty_project, pending_delete: true)
project = build(:empty_project, pending_delete: true, namespace_id: nil)
project.save(validate: false)
expect(NamespacelessProjectDestroyWorker).to receive(:bulk_perform_async).with([[project.id.to_s, admin.id, {}]])
expect(NamespacelessProjectDestroyWorker).to receive(:bulk_perform_async).with([[project.id.to_s]])
described_class.new.up
end
it 'does nothing when no pending delete projects without namespace found' do
create(:empty_project)
create(:empty_project, pending_delete: true)
expect(NamespacelessProjectDestroyWorker).not_to receive(:bulk_perform_async)
described_class.new.up
end

View file

@ -14,15 +14,13 @@ describe NamespacelessProjectDestroyWorker do
it 'does not do anything' do
project = create(:empty_project)
subject.perform(project.id, project.owner.id, {})
subject.perform(project.id)
expect(Project.unscoped.all).to include(project)
end
end
context 'project has no namespace' do
let(:admin) { create(:admin) }
let!(:project) do
project = build(:empty_project, namespace_id: nil)
project.save(validate: false)
@ -33,11 +31,11 @@ describe NamespacelessProjectDestroyWorker do
it "truncates the project's team" do
expect_any_instance_of(ProjectTeam).to receive(:truncate)
subject.perform(project.id, admin.id, {})
subject.perform(project.id)
end
it 'deletes the project' do
subject.perform(project.id, admin.id, {})
subject.perform(project.id)
expect(Project.unscoped.all).not_to include(project)
end
@ -45,13 +43,13 @@ describe NamespacelessProjectDestroyWorker do
it 'does not call unlink_fork' do
is_expected.not_to receive(:unlink_fork)
subject.perform(project.id, admin.id, {})
subject.perform(project.id)
end
it 'does not do anything in Project#remove_pages method' do
expect(Gitlab::PagesTransfer).not_to receive(:new)
subject.perform(project.id, admin.id, {})
subject.perform(project.id)
end
end
@ -65,13 +63,13 @@ describe NamespacelessProjectDestroyWorker do
it 'closes open merge requests' do
merge_request = create(:merge_request, source_project: project, target_project: parent_project)
subject.perform(project.id, admin.id, {})
subject.perform(project.id)
expect(merge_request.reload).to be_closed
end
it 'destroys the link' do
subject.perform(project.id, admin.id, {})
subject.perform(project.id)
expect(parent_project.forked_project_links).to be_empty
end