Welcome to mirror list, hosted at ThFree Co, Russian Federation.

remove_expired_members_worker.rb « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fc2ec047e1c14039bd928d826bb3c9524b2fe7f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

class RemoveExpiredMembersWorker # rubocop:disable Scalability/IdempotentWorker
  include ApplicationWorker
  include CronjobQueue

  feature_category :authentication_and_authorization
  worker_resource_boundary :cpu

  # rubocop: disable CodeReuse/ActiveRecord
  def perform
    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

        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}")
    end
  end
  # rubocop: enable CodeReuse/ActiveRecord
end