summaryrefslogtreecommitdiff
path: root/lib/constraints/admin_constrainer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/constraints/admin_constrainer.rb')
-rw-r--r--lib/constraints/admin_constrainer.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/constraints/admin_constrainer.rb b/lib/constraints/admin_constrainer.rb
new file mode 100644
index 00000000000..59c855a1b73
--- /dev/null
+++ b/lib/constraints/admin_constrainer.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module Constraints
+ class AdminConstrainer
+ def matches?(request)
+ if Feature.enabled?(:user_mode_in_session)
+ 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