From 59eca3ecdb12ed7a8885edc9b80010bda92882ac Mon Sep 17 00:00:00 2001 From: Sergey Galich Date: Tue, 16 Apr 2024 23:50:03 +0000 Subject: [PATCH] Bug 1891884 - Allowing to dismiss breach alerts in Megalist r=issammani Differential Revision: https://phabricator.services.mozilla.com/D207648 --- .../aboutlogins/LoginBreaches.sys.mjs | 5 ++++ .../megalist/MegalistViewModel.sys.mjs | 14 ++++++++-- .../datasources/BankCardDataSource.sys.mjs | 2 +- .../datasources/LoginDataSource.sys.mjs | 28 +++++++++++++++---- .../satchel/megalist/content/megalist.ftl | 1 + 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/browser/components/aboutlogins/LoginBreaches.sys.mjs b/browser/components/aboutlogins/LoginBreaches.sys.mjs index 2fe1c682a5b8..496e5de57515 100644 --- a/browser/components/aboutlogins/LoginBreaches.sys.mjs +++ b/browser/components/aboutlogins/LoginBreaches.sys.mjs @@ -147,6 +147,11 @@ export const LoginBreaches = { return vulnerablePasswordsByLoginGUID; }, + recordBreachAlertDismissal(loginGuid) { + const storageJSON = Services.logins.wrappedJSObject._storage; + return storageJSON.recordBreachAlertDismissal(loginGuid); + }, + isVulnerablePassword(login) { if (!lazy.VULNERABLE_PASSWORDS_ENABLED) { return false; diff --git a/toolkit/components/satchel/megalist/MegalistViewModel.sys.mjs b/toolkit/components/satchel/megalist/MegalistViewModel.sys.mjs index dd426e47af3a..17c5c5299039 100644 --- a/toolkit/components/satchel/megalist/MegalistViewModel.sys.mjs +++ b/toolkit/components/satchel/megalist/MegalistViewModel.sys.mjs @@ -67,6 +67,13 @@ export class MegalistViewModel { } } + #commandsArray(snapshot) { + if (Array.isArray(snapshot.commands)) { + return snapshot.commands; + } + return Array.from(snapshot.commands()); + } + /** * * Send snapshot of necessary line data across parent-child boundary. @@ -95,7 +102,7 @@ export class MegalistViewModel { snapshot.end = snapshotData.end; } if ("commands" in snapshotData) { - snapshot.commands = snapshotData.commands; + snapshot.commands = this.#commandsArray(snapshotData); } if ("valueIcon" in snapshotData) { snapshot.valueIcon = snapshotData.valueIcon; @@ -182,8 +189,9 @@ export class MegalistViewModel { : this.#selectedIndex; const snapshot = this.#snapshots[index]; if (snapshot) { - commandId = commandId ?? snapshot.commands[0]?.id; - const mustVerify = snapshot.commands.find(c => c.id == commandId)?.verify; + const commands = this.#commandsArray(snapshot); + commandId = commandId ?? commands[0]?.id; + const mustVerify = commands.find(c => c.id == commandId)?.verify; if (!mustVerify || (await this.#verifyUser())) { // TODO:Enter the prompt message and pref for #verifyUser() await snapshot[`execute${commandId}`]?.(value); diff --git a/toolkit/components/satchel/megalist/aggregator/datasources/BankCardDataSource.sys.mjs b/toolkit/components/satchel/megalist/aggregator/datasources/BankCardDataSource.sys.mjs index 3f6791ef1c88..e1f7354e223e 100644 --- a/toolkit/components/satchel/megalist/aggregator/datasources/BankCardDataSource.sys.mjs +++ b/toolkit/components/satchel/megalist/aggregator/datasources/BankCardDataSource.sys.mjs @@ -266,7 +266,7 @@ export class BankCardDataSource extends DataSourceBase { `${card["cc-exp-month"]}/${card["cc-exp-year"]}` .toUpperCase() .includes(searchText) || - card["cc-name"].toUpperCase().includes(searchText) + card["cc-name"]?.toUpperCase().includes(searchText) ); this.formatMessages({ diff --git a/toolkit/components/satchel/megalist/aggregator/datasources/LoginDataSource.sys.mjs b/toolkit/components/satchel/megalist/aggregator/datasources/LoginDataSource.sys.mjs index 0d3917d876ff..c7e7844da4b4 100644 --- a/toolkit/components/satchel/megalist/aggregator/datasources/LoginDataSource.sys.mjs +++ b/toolkit/components/satchel/megalist/aggregator/datasources/LoginDataSource.sys.mjs @@ -63,10 +63,15 @@ export class LoginDataSource extends DataSourceBase { "passwords-import-file-picker-csv-filter-title", passwordsImportFilePickerTsvFilterTitle: "passwords-import-file-picker-tsv-filter-title", + dismissBreachCommandLabel: "passwords-dismiss-breach-alert-command", }).then(strings => { const copyCommand = { id: "Copy", label: strings.copyCommandLabel }; const editCommand = { id: "Edit", label: strings.editCommandLabel }; const deleteCommand = { id: "Delete", label: strings.deleteCommandLabel }; + const dismissBreachCommand = { + id: "DismissBreach", + label: strings.dismissBreachCommandLabel, + }; const noOriginSticker = { type: "error", label: "😾 Missing origin" }; const noPasswordSticker = { type: "error", label: "😾 Missing password" }; const breachedSticker = { type: "warning", label: "BREACH" }; @@ -115,12 +120,23 @@ export class LoginDataSource extends DataSourceBase { }, }, commands: { - value: [ - { id: "Open", label: strings.openCommandLabel }, - copyCommand, - "-", - deleteCommand, - ], + *value() { + yield { id: "Open", label: strings.openCommandLabel }; + yield copyCommand; + yield "-"; + yield deleteCommand; + + if (this.breached) { + yield dismissBreachCommand; + } + }, + }, + executeDismissBreach: { + value() { + lazy.LoginBreaches.recordBreachAlertDismissal(this.record.guid); + delete this.breached; + this.refreshOnScreen(); + }, }, executeCopy: { value() { diff --git a/toolkit/components/satchel/megalist/content/megalist.ftl b/toolkit/components/satchel/megalist/content/megalist.ftl index 69d085a7c5b9..c1dd53303c6d 100644 --- a/toolkit/components/satchel/megalist/content/megalist.ftl +++ b/toolkit/components/satchel/megalist/content/megalist.ftl @@ -23,6 +23,7 @@ command-cancel = Cancel passwords-section-label = Passwords passwords-disabled = Passwords are disabled +passwords-dismiss-breach-alert-command = Dismiss breach alert passwords-command-create = Add Password passwords-command-import = Import from a File… passwords-command-export = Export Passwords…