2018-06-27 07:23:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-02-19 18:09:10 +00:00
|
|
|
class RemoveExpiredMembersWorker # rubocop:disable Scalability/IdempotentWorker
|
2017-11-28 16:08:30 +00:00
|
|
|
include ApplicationWorker
|
2021-04-30 18:10:09 +00:00
|
|
|
|
2021-07-21 12:09:35 +00:00
|
|
|
data_consistency :always
|
|
|
|
|
2021-03-22 15:09:31 +00:00
|
|
|
include CronjobQueue
|
2016-08-04 07:41:29 +00:00
|
|
|
|
2019-10-18 11:11:44 +00:00
|
|
|
feature_category :authentication_and_authorization
|
2019-10-30 15:14:17 +00:00
|
|
|
worker_resource_boundary :cpu
|
2019-10-18 11:11:44 +00:00
|
|
|
|
2020-11-09 12:09:24 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-08-04 07:41:29 +00:00
|
|
|
def perform
|
2021-03-22 15:09:31 +00:00
|
|
|
Member.expired.preload(:user, :source).find_each do |member|
|
|
|
|
context = {
|
|
|
|
user: member.user,
|
|
|
|
# The ApplicationContext will reject type-mismatches. So a GroupMemeber will only populate `namespace`.
|
|
|
|
# while a `ProjectMember` will populate `project
|
|
|
|
project: member.source,
|
|
|
|
namespace: member.source
|
|
|
|
}
|
|
|
|
with_context(context) do
|
|
|
|
Members::DestroyService.new.execute(member, skip_authorization: true)
|
2020-11-09 12:09:24 +00:00
|
|
|
|
2021-03-22 15:09:31 +00:00
|
|
|
expired_user = member.user
|
2020-11-09 12:09:24 +00:00
|
|
|
|
2021-03-22 15:09:31 +00:00
|
|
|
if expired_user.project_bot?
|
|
|
|
Users::DestroyService.new(nil).execute(expired_user, skip_authorization: true)
|
|
|
|
end
|
2020-11-09 12:09:24 +00:00
|
|
|
end
|
2021-04-26 12:09:44 +00:00
|
|
|
rescue StandardError => ex
|
2019-03-13 13:42:43 +00:00
|
|
|
logger.error("Expired Member ID=#{member.id} cannot be removed - #{ex}")
|
2016-08-04 07:41:29 +00:00
|
|
|
end
|
|
|
|
end
|
2020-11-09 12:09:24 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-08-04 07:41:29 +00:00
|
|
|
end
|