debian-mirror-gitlab/app/workers/namespaceless_project_destroy_worker.rb

41 lines
1.1 KiB
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
# Worker to destroy projects that do not have a namespace
#
# It destroys everything it can without having the info about the namespace it
# used to belong to. Projects in this state should be rare.
# The worker will reject doing anything for projects that *do* have a
# namespace. For those use ProjectDestroyWorker instead.
2020-04-08 14:13:33 +05:30
class NamespacelessProjectDestroyWorker # rubocop:disable Scalability/IdempotentWorker
2018-03-17 18:26:18 +05:30
include ApplicationWorker
2021-06-08 01:23:25 +05:30
sidekiq_options retry: 3
2018-03-17 18:26:18 +05:30
include ExceptionBacktrace
2017-09-10 17:25:29 +05:30
2019-12-21 20:55:43 +05:30
feature_category :authentication_and_authorization
2017-09-10 17:25:29 +05:30
def perform(project_id)
begin
project = Project.unscoped.find(project_id)
rescue ActiveRecord::RecordNotFound
return
end
2018-03-17 18:26:18 +05:30
2019-03-02 22:35:43 +05:30
return if project.namespace # Reject doing anything for projects that *do* have a namespace
2017-09-10 17:25:29 +05:30
project.team.truncate
unlink_fork(project) if project.forked?
project.destroy!
end
private
def unlink_fork(project)
merge_requests = project.forked_from_project.merge_requests.opened.from_project(project)
2019-12-21 20:55:43 +05:30
merge_requests.update_all(state_id: MergeRequest.available_states[:closed])
2017-09-10 17:25:29 +05:30
end
end