summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2017-05-09 22:16:52 +0200
committerToon Claes <toon@gitlab.com>2017-05-10 15:01:27 +0200
commit37a79409d446955eeb443ea5397d5bf263601a2d (patch)
treec3e9ada5f5f50e11a48feb4e5edf2837963eafc3
parent0ad80cab40097658b1eec5b87d440cfcd60d2755 (diff)
downloadgitlab-ce-37a79409d446955eeb443ea5397d5bf263601a2d.tar.gz
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.
-rw-r--r--app/workers/namespaceless_project_destroy_worker.rb5
-rw-r--r--db/post_migrate/20170502101023_cleanup_namespaceless_pending_delete_projects.rb9
-rw-r--r--spec/migrations/cleanup_namespaceless_pending_delete_projects_spec.rb12
-rw-r--r--spec/workers/namespaceless_project_destroy_worker_spec.rb16
4 files changed, 21 insertions, 21 deletions
diff --git a/app/workers/namespaceless_project_destroy_worker.rb b/app/workers/namespaceless_project_destroy_worker.rb
index da02084c688..bfae0c77700 100644
--- a/app/workers/namespaceless_project_destroy_worker.rb
+++ b/app/workers/namespaceless_project_destroy_worker.rb
@@ -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?
diff --git a/db/post_migrate/20170502101023_cleanup_namespaceless_pending_delete_projects.rb b/db/post_migrate/20170502101023_cleanup_namespaceless_pending_delete_projects.rb
index 76ed109898b..2d242da9ef8 100644
--- a/db/post_migrate/20170502101023_cleanup_namespaceless_pending_delete_projects.rb
+++ b/db/post_migrate/20170502101023_cleanup_namespaceless_pending_delete_projects.rb
@@ -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
diff --git a/spec/migrations/cleanup_namespaceless_pending_delete_projects_spec.rb b/spec/migrations/cleanup_namespaceless_pending_delete_projects_spec.rb
index cee12d521dc..0b8af5010ba 100644
--- a/spec/migrations/cleanup_namespaceless_pending_delete_projects_spec.rb
+++ b/spec/migrations/cleanup_namespaceless_pending_delete_projects_spec.rb
@@ -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
diff --git a/spec/workers/namespaceless_project_destroy_worker_spec.rb b/spec/workers/namespaceless_project_destroy_worker_spec.rb
index ed78236ebc0..8533b7b85e9 100644
--- a/spec/workers/namespaceless_project_destroy_worker_spec.rb
+++ b/spec/workers/namespaceless_project_destroy_worker_spec.rb
@@ -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