A platform for community discussion. Free, open, simple.
FIX: Don't update last_seen_at when impersonating a user (#34872)
Ted Johansson064aba3010e0
diff --git a/lib/auth/default_current_user_provider.rb b/lib/auth/default_current_user_provider.rbindex 8ef8e72466f..2b37c1252d7 100644--- a/lib/auth/default_current_user_provider.rb+++ b/lib/auth/default_current_user_provider.rb@@ -209,7 +209,7 @@ class Auth::DefaultCurrentUserProvider# under no conditions to suspended or inactive accounts get current_usercurrent_user = nil if current_user && (current_user.suspended? || !current_user.active)- if current_user && should_update_last_seen?+ if current_user && !current_user.is_impersonating && should_update_last_seen?ip = request.ipuser_id = current_user.idold_ip = current_user.ip_addressdiff --git a/spec/lib/auth/default_current_user_provider_spec.rb b/spec/lib/auth/default_current_user_provider_spec.rbindex ef165a27156..6d3c9bf8b2f 100644--- a/spec/lib/auth/default_current_user_provider_spec.rb+++ b/spec/lib/auth/default_current_user_provider_spec.rb@@ -285,6 +285,19 @@ RSpec.describe Auth::DefaultCurrentUserProvider doendend+ describe "when impersonating another user" do+ it "should not update User#last_seen_at" do+ old_timestamp = 1.week.ago+ user.update!(last_seen_at: old_timestamp)+ User.any_instance.stubs(:is_impersonating).returns(true)++ provider2 = provider("/", "HTTP_COOKIE" => "_t=#{cookie}")+ u = provider2.current_user++ expect(u.reload.last_seen_at).to eq_time(old_timestamp)+ end+ end+it "should not cache an invalid user when Rails hasn't set `path_parameters` on the request yet" doSiteSetting.login_required = trueuser = Fabricate(:user)