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

client.rb « admin_mode « sidekiq_middleware « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 36204e1bee0bcfe6232d3a885402ac3db8834e72 (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

module Gitlab
  module SidekiqMiddleware
    module AdminMode
      # Checks if admin mode is enabled for the request creating the sidekiq job
      # by examining if admin mode has been enabled for the user
      # If enabled then it injects a job field that persists through the job execution
      class Client
        def call(_worker_class, job, _queue, _redis_pool)
          return yield unless ::Feature.enabled?(:user_mode_in_session)

          # Admin mode enabled in the original request or in a nested sidekiq job
          admin_mode_user_id = find_admin_user_id

          if admin_mode_user_id
            job['admin_mode_user_id'] ||= admin_mode_user_id

            ::Gitlab::AppLogger.debug("AdminMode::Client injected admin mode for job: #{job.inspect}")
          end

          yield
        end

        private

        def find_admin_user_id
          ::Gitlab::Auth::CurrentUserMode.current_admin&.id ||
            ::Gitlab::Auth::CurrentUserMode.bypass_session_admin_id
        end
      end
    end
  end
end