diff --git a/app/models/active_session.rb b/app/models/active_session.rb index 16687e22fc163b110c9d7108df9b90d69c57a3cc..2eb9c9bca7f24730c3de04caf629006261b51368 100644 --- a/app/models/active_session.rb +++ b/app/models/active_session.rb @@ -27,7 +27,7 @@ class ActiveSession attr_accessor :ip_address, :browser, :os, :device_name, :device_type, - :is_impersonated, :session_id, :session_private_id, :admin_mode + :is_impersonated, :session_id, :session_private_id attr_reader :created_at, :updated_at @@ -80,8 +80,7 @@ def self.set(user, request) created_at: user.current_sign_in_at || timestamp, updated_at: timestamp, session_private_id: session_private_id, - is_impersonated: request.session[:impersonator_id].present?, - admin_mode: Gitlab::Auth::CurrentUserMode.new(user, request.session).admin_mode? + is_impersonated: request.session[:impersonator_id].present? ) Gitlab::Instrumentation::RedisClusterValidator.allow_cross_slot_commands do diff --git a/app/views/user_settings/active_sessions/_active_session.html.haml b/app/views/user_settings/active_sessions/_active_session.html.haml index d3ddafd244835c7e4e4bdedeb3168affa86e87cc..e91c28e6e84ddb8c994bc0aa3c0c99b33047061b 100644 --- a/app/views/user_settings/active_sessions/_active_session.html.haml +++ b/app/views/user_settings/active_sessions/_active_session.html.haml @@ -24,8 +24,6 @@ %strong= _('Signed in') = s_('ProfileSession|on') = l(active_session.created_at, format: :short) - - if active_session.admin_mode - %strong= _('with Admin Mode') - unless is_current_session .float-right diff --git a/lib/gitlab/auth/current_user_mode.rb b/lib/gitlab/auth/current_user_mode.rb index c1a9c280336a9a24c17b3d0206602c0dc3703dc3..9bd4711c4bbf16bf3c5993d76e90d07160b01c42 100644 --- a/lib/gitlab/auth/current_user_mode.rb +++ b/lib/gitlab/auth/current_user_mode.rb @@ -8,7 +8,6 @@ module Auth # an administrator must have explicitly enabled admin-mode # e.g. on web access require re-authentication class CurrentUserMode - include Gitlab::Utils::StrongMemoize NotRequestedError = Class.new(StandardError) # RequestStore entries @@ -86,9 +85,8 @@ def current_admin end end - def initialize(user, session = nil) + def initialize(user) @user = user - @session = session end def admin_mode? @@ -140,15 +138,6 @@ def request_admin_mode! current_session_data[ADMIN_MODE_REQUESTED_TIME_KEY] = Time.now end - def current_session_data - if @session.present? - Gitlab::NamespacedSessionStore.new(SESSION_STORE_KEY, @session) - else - Gitlab::NamespacedSessionStore.new(SESSION_STORE_KEY) - end - end - strong_memoize_attr :current_session_data - private attr_reader :user @@ -163,6 +152,10 @@ def admin_mode_requested_rs_key @admin_mode_requested_rs_key ||= { res: :current_user_mode, user: user.id, method: :admin_mode_requested? } end + def current_session_data + @current_session ||= Gitlab::NamespacedSessionStore.new(SESSION_STORE_KEY) + end + def session_with_admin_mode? return true if bypass_session? diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 7b59eded61febb746aa8e5df27ed39689ab7850f..4d794d62d1a895d1862e480fee7015654ea1bbf0 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -59865,9 +59865,6 @@ msgstr "" msgid "with %{additions} additions, %{deletions} deletions." msgstr "" -msgid "with Admin Mode" -msgstr "" - msgid "with expiry changing from %{old_expiry} to %{new_expiry}" msgstr "" diff --git a/spec/features/user_settings/active_sessions_spec.rb b/spec/features/user_settings/active_sessions_spec.rb index 586700249854b41d30d9f2701ecd9063127874ec..bc0693d79e1f820b6d59cbca930af602bd56b35b 100644 --- a/spec/features/user_settings/active_sessions_spec.rb +++ b/spec/features/user_settings/active_sessions_spec.rb @@ -82,26 +82,6 @@ end end - it 'admin sees if the session is with admin mode', :enable_admin_mode do - Capybara::Session.new(:admin_session) - - using_session :admin_session do - gitlab_sign_in(admin) - visit user_settings_active_sessions_path - expect(page).to have_content('with Admin Mode') - end - end - - it 'does not display admin mode text in case its not' do - Capybara::Session.new(:admin_session) - - using_session :admin_session do - gitlab_sign_in(admin) - visit user_settings_active_sessions_path - expect(page).not_to have_content('with Admin Mode') - end - end - it 'user can revoke a session', :js do Capybara::Session.new(:session1) Capybara::Session.new(:session2) diff --git a/spec/lib/gitlab/auth/current_user_mode_spec.rb b/spec/lib/gitlab/auth/current_user_mode_spec.rb index 74860cbf8216ce0cd4e5b25786f31a788bac345e..650af6af22961c691f58105147086e2f774cf533 100644 --- a/spec/lib/gitlab/auth/current_user_mode_spec.rb +++ b/spec/lib/gitlab/auth/current_user_mode_spec.rb @@ -7,63 +7,6 @@ subject { described_class.new(user) } - describe '#initialize' do - context 'with user' do - around do |example| - Gitlab::Session.with_session(nil) do - example.run - end - end - - it 'has no session' do - subject - expect(Gitlab::Session.current).to be_nil - end - end - - context 'with user and session' do - include_context 'custom session' - let(:session) { { 'key' => "value" } } - - it 'has a session' do - described_class.new(user, session) - expect(Gitlab::Session.current).to eq(session) - end - end - end - - describe '#current_session_data' do - context 'without session' do - around do |example| - Gitlab::Session.with_session(nil) do - example.run - end - end - - it 'new session is created' do - expect(Gitlab::Session.current).to be_nil - expect(Gitlab::NamespacedSessionStore).to receive(:new).with(described_class::SESSION_STORE_KEY) - - subject.current_session_data - end - end - - context 'with session' do - include_context 'custom session' - let(:session) { { 'key' => "value" } } - - it 'session is still the same' do - expect(Gitlab::Session.current).to eq(session) - subject = described_class.new(user, session) - - expect(Gitlab::NamespacedSessionStore).to receive(:new).with(described_class::SESSION_STORE_KEY, session) - - subject.current_session_data - expect(Gitlab::Session.current).to eq(session) - end - end - end - context 'when session is available' do include_context 'custom session'