1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-23 03:33:54 +00:00

[PM-14236] most recently used login is no longer moved to top of the list (#16388)

* PM-14236 add overlay background call to internal autofill

* update overlay background to handel vaultAutofillSuggestionUsed call

* update main and runtime to pass message

* add rough testing to verify calls are being made or not

* remove spacing

* reduce scope and handle update in main background

* clean type, remove cipherId which is no longer used

* when keyboard shortcut is used, update overlay ciphers to freflect new order immediately

* keep separation of concerns, put handleAutofillSuggestionUsed back in overlay, add tests

* reduced approach
This commit is contained in:
Daniel Riera
2025-10-06 10:48:03 -04:00
committed by GitHub
parent 6cbdecef43
commit 2ce194c190
3 changed files with 41 additions and 0 deletions

View File

@@ -145,6 +145,7 @@ export default class RuntimeBackground {
if (totpCode != null) { if (totpCode != null) {
this.platformUtilsService.copyToClipboard(totpCode); this.platformUtilsService.copyToClipboard(totpCode);
} }
await this.main.updateOverlayCiphers();
break; break;
} }
case ExtensionCommand.AutofillCard: { case ExtensionCommand.AutofillCard: {

View File

@@ -204,6 +204,7 @@ describe("VaultPopupAutofillService", () => {
describe("doAutofill()", () => { describe("doAutofill()", () => {
it("should return true if autofill is successful", async () => { it("should return true if autofill is successful", async () => {
mockCipher.id = "test-cipher-id";
mockAutofillService.doAutoFill.mockResolvedValue(null); mockAutofillService.doAutoFill.mockResolvedValue(null);
const result = await service.doAutofill(mockCipher); const result = await service.doAutofill(mockCipher);
expect(result).toBe(true); expect(result).toBe(true);
@@ -251,6 +252,7 @@ describe("VaultPopupAutofillService", () => {
}); });
it("should copy TOTP code to clipboard if available", async () => { it("should copy TOTP code to clipboard if available", async () => {
mockCipher.id = "test-cipher-id-with-totp";
const totpCode = "123456"; const totpCode = "123456";
mockAutofillService.doAutoFill.mockResolvedValue(totpCode); mockAutofillService.doAutoFill.mockResolvedValue(totpCode);
await service.doAutofill(mockCipher); await service.doAutofill(mockCipher);
@@ -405,5 +407,26 @@ describe("VaultPopupAutofillService", () => {
}); });
}); });
}); });
describe("handleAutofillSuggestionUsed", () => {
const cipherId = "cipher-123";
beforeEach(() => {
mockCipherService.updateLastUsedDate.mockResolvedValue(undefined);
});
it("updates last used date when there is an active user", async () => {
await service.handleAutofillSuggestionUsed({ cipherId });
expect(mockCipherService.updateLastUsedDate).toHaveBeenCalledTimes(1);
expect(mockCipherService.updateLastUsedDate).toHaveBeenCalledWith(cipherId, mockUserId);
});
it("does nothing when there is no active user", async () => {
accountService.activeAccount$ = of(null);
await service.handleAutofillSuggestionUsed({ cipherId });
expect(mockCipherService.updateLastUsedDate).not.toHaveBeenCalled();
});
});
}); });
}); });

View File

@@ -16,6 +16,7 @@ import {
} from "rxjs"; } from "rxjs";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getOptionalUserId } from "@bitwarden/common/auth/services/account.service";
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service"; import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
import { isUrlInList } from "@bitwarden/common/autofill/utils"; import { isUrlInList } from "@bitwarden/common/autofill/utils";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
@@ -268,6 +269,7 @@ export class VaultPopupAutofillService {
}); });
return false; return false;
} }
await this.handleAutofillSuggestionUsed({ cipherId: cipher.id });
return true; return true;
} }
@@ -326,6 +328,21 @@ export class VaultPopupAutofillService {
return didAutofill; return didAutofill;
} }
/**
* When a user autofills with an autofill suggestion outside of the inline menu,
* update the cipher's last used date.
*
* @param message - The message containing the cipher ID that was used
*/
async handleAutofillSuggestionUsed(message: { cipherId: string }) {
const activeUserId = await firstValueFrom(
this.accountService.activeAccount$.pipe(getOptionalUserId),
);
if (activeUserId) {
await this.cipherService.updateLastUsedDate(message.cipherId, activeUserId);
}
}
/** /**
* Attempts to autofill the given cipher and, upon successful autofill, saves the URI to the cipher. * Attempts to autofill the given cipher and, upon successful autofill, saves the URI to the cipher.
* Will copy any TOTP code to the clipboard if available after successful autofill. * Will copy any TOTP code to the clipboard if available after successful autofill.