2018-06-27 03:23:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-02-19 13:09:10 -05:00
|
|
|
class RemoveExpiredMembersWorker # rubocop:disable Scalability/IdempotentWorker
|
2017-11-28 11:08:30 -05:00
|
|
|
include ApplicationWorker
|
2021-04-30 14:10:09 -04:00
|
|
|
|
2021-07-21 08:09:35 -04:00
|
|
|
data_consistency :always
|
|
|
|
|
2021-03-22 11:09:31 -04:00
|
|
|
include CronjobQueue
|
2016-08-04 03:41:29 -04:00
|
|
|
|
2019-10-18 07:11:44 -04:00
|
|
|
feature_category :authentication_and_authorization
|
2019-10-30 11:14:17 -04:00
|
|
|
worker_resource_boundary :cpu
|
2019-10-18 07:11:44 -04:00
|
|
|
|
2020-11-09 07:09:24 -05:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-08-04 03:41:29 -04:00
|
|
|
def perform
|
2021-03-22 11:09:31 -04: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 07:09:24 -05:00
|
|
|
|
2021-03-22 11:09:31 -04:00
|
|
|
expired_user = member.user
|
2020-11-09 07:09:24 -05:00
|
|
|
|
2021-03-22 11:09:31 -04:00
|
|
|
if expired_user.project_bot?
|
|
|
|
Users::DestroyService.new(nil).execute(expired_user, skip_authorization: true)
|
|
|
|
end
|
2020-11-09 07:09:24 -05:00
|
|
|
end
|
2021-04-26 08:09:44 -04:00
|
|
|
rescue StandardError => ex
|
2019-03-13 09:42:43 -04:00
|
|
|
logger.error("Expired Member ID=#{member.id} cannot be removed - #{ex}")
|
2016-08-04 03:41:29 -04:00
|
|
|
end
|
|
|
|
end
|
2020-11-09 07:09:24 -05:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-08-04 03:41:29 -04:00
|
|
|
end
|