2020-04-15 11:09:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Constraints
|
|
|
|
class AdminConstrainer
|
|
|
|
def matches?(request)
|
2021-03-17 20:08:58 -04:00
|
|
|
if Gitlab::CurrentSettings.admin_mode
|
2020-04-15 11:09:17 -04:00
|
|
|
admin_mode_enabled?(request)
|
|
|
|
else
|
|
|
|
user_is_admin?(request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def user_is_admin?(request)
|
|
|
|
request.env['warden'].authenticate? && request.env['warden'].user.admin?
|
|
|
|
end
|
|
|
|
|
|
|
|
def admin_mode_enabled?(request)
|
|
|
|
Gitlab::Session.with_session(request.session) do
|
|
|
|
request.env['warden'].authenticate? && Gitlab::Auth::CurrentUserMode.new(request.env['warden'].user).admin_mode?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|