Commit 3188dd21 authored by Imre Farkas's avatar Imre Farkas

Merge branch 'bvl-add-context-to-member-expiry' into 'master'

This adds a context around expiring members

See merge request gitlab-org/gitlab!57028
parents f9b157fe cfff0a4f
......@@ -2,20 +2,29 @@
class RemoveExpiredMembersWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
include CronjobQueue
feature_category :authentication_and_authorization
worker_resource_boundary :cpu
# rubocop: disable CodeReuse/ActiveRecord
def perform
Member.expired.preload(:user).find_each do |member|
Members::DestroyService.new.execute(member, skip_authorization: true)
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)
expired_user = member.user
expired_user = member.user
if expired_user.project_bot?
Users::DestroyService.new(nil).execute(expired_user, skip_authorization: true)
if expired_user.project_bot?
Users::DestroyService.new(nil).execute(expired_user, skip_authorization: true)
end
end
rescue => ex
logger.error("Expired Member ID=#{member.id} cannot be removed - #{ex}")
......
......@@ -29,6 +29,15 @@ RSpec.describe RemoveExpiredMembersWorker do
worker.perform
expect(non_expiring_project_member.reload).to be_present
end
it 'adds context to resulting jobs' do
worker.perform
new_job = Sidekiq::Worker.jobs.last
expect(new_job).to include('meta.project' => expired_project_member.project.full_path,
'meta.user' => expired_project_member.user.username)
end
end
context 'project bots' do
......@@ -98,6 +107,15 @@ RSpec.describe RemoveExpiredMembersWorker do
worker.perform
expect(non_expiring_group_member.reload).to be_present
end
it 'adds context to resulting jobs' do
worker.perform
new_job = Sidekiq::Worker.jobs.last
expect(new_job).to include('meta.root_namespace' => expired_group_member.group.full_path,
'meta.user' => expired_group_member.user.username)
end
end
context 'when the last group owner expires' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment