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

recalculate_project_authorizations_with_min_max_user_id.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b66fdfd5c65745896185779fd4b70d2d2afccacc (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
35
36
37
38
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # rubocop:disable Style/Documentation
    class RecalculateProjectAuthorizationsWithMinMaxUserId
      def perform(min_user_id, max_user_id)
        User.where(id: min_user_id..max_user_id).find_each do |user|
          service = Users::RefreshAuthorizedProjectsService.new(
            user,
            incorrect_auth_found_callback:
              ->(project_id, access_level) do
                logger.info(message: 'Removing ProjectAuthorizations',
                            user_id: user.id,
                            project_id: project_id,
                            access_level: access_level)
              end,
            missing_auth_found_callback:
              ->(project_id, access_level) do
                logger.info(message: 'Creating ProjectAuthorizations',
                            user_id: user.id,
                            project_id: project_id,
                            access_level: access_level)
              end
          )

          service.execute
        end
      end

      private

      def logger
        @logger ||= Gitlab::BackgroundMigration::Logger.build
      end
    end
  end
end