mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 13:35:24 +08:00
FIX: ManagedAuthenticator should automatically update last_used time
This commit is contained in:
@ -45,6 +45,8 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
|
|||||||
association.credentials = auth_token[:credentials] || {}
|
association.credentials = auth_token[:credentials] || {}
|
||||||
association.extra = auth_token[:extra] || {}
|
association.extra = auth_token[:extra] || {}
|
||||||
|
|
||||||
|
association.last_used = Time.zone.now
|
||||||
|
|
||||||
# Save to the DB. Do this even if we don't have a user - it might be linked up later in after_create_account
|
# Save to the DB. Do this even if we don't have a user - it might be linked up later in after_create_account
|
||||||
association.save!
|
association.save!
|
||||||
|
|
||||||
|
@ -39,11 +39,12 @@ describe Auth::ManagedAuthenticator do
|
|||||||
describe 'after_authenticate' do
|
describe 'after_authenticate' do
|
||||||
it 'can match account from an existing association' do
|
it 'can match account from an existing association' do
|
||||||
user = Fabricate(:user)
|
user = Fabricate(:user)
|
||||||
associated = UserAssociatedAccount.create!(user: user, provider_name: 'myauth', provider_uid: "1234")
|
associated = UserAssociatedAccount.create!(user: user, provider_name: 'myauth', provider_uid: "1234", last_used: 1.year.ago)
|
||||||
result = authenticator.after_authenticate(hash)
|
result = authenticator.after_authenticate(hash)
|
||||||
|
|
||||||
expect(result.user.id).to eq(user.id)
|
expect(result.user.id).to eq(user.id)
|
||||||
associated.reload
|
associated.reload
|
||||||
|
expect(associated.last_used).to be >= 1.day.ago
|
||||||
expect(associated.info["name"]).to eq("Best Display Name")
|
expect(associated.info["name"]).to eq("Best Display Name")
|
||||||
expect(associated.info["email"]).to eq("awesome@example.com")
|
expect(associated.info["email"]).to eq("awesome@example.com")
|
||||||
expect(associated.credentials["token"]).to eq("supersecrettoken")
|
expect(associated.credentials["token"]).to eq("supersecrettoken")
|
||||||
|
Reference in New Issue
Block a user