Skip to content

Commit

Permalink
Fixes #38037 - Update last login time for External Auth user
Browse files Browse the repository at this point in the history
  • Loading branch information
hao-yu authored and ofedoren committed Feb 14, 2025
1 parent 1434f39 commit 71fc34b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ def self.find_or_create_external_user(attrs, auth_source_name)
user.usergroups = new_usergroups.uniq
end

user.post_successful_login
user
# not existing user and creating is disabled by settings
elsif auth_source_name.nil?
Expand Down
13 changes: 9 additions & 4 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,15 @@ def setup_user(operation, type = 'users', search = nil)

context "internal or not existing AuthSource" do
test 'existing user without auth source specified' do
assert_difference('User.count', 0) do
login = users(:external).login
user = User.find_or_create_external_user({:login => login}, nil)
assert_equal user, users(:external)
# If a user is found, it is set as User.current.
# Because this user doesn't have permissions to view other users, we
# need to unscope the query to count the existing users
assert_difference('User.unscoped.count', 0) do
user = users(:external)
found_user = User.find_or_create_external_user({:login => user.login}, nil)

assert_equal found_user, user
assert_operator user.last_login_on, :<, found_user.last_login_on
end
end

Expand Down

0 comments on commit 71fc34b

Please sign in to comment.