From 0da681f0741edab149c9f490b11882b1aa8aaa91 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Thu, 27 Jan 2022 23:07:34 +0100 Subject: [PATCH] OpenPGP.js now stores keys in localStorage Renamed all deleteAccess to askDelete --- dev/External/ko.js | 4 +-- dev/Model/Account.js | 2 +- dev/Model/Filter.js | 2 +- dev/Model/FolderCollection.js | 2 +- dev/Model/Identity.js | 2 +- dev/Model/SieveScript.js | 2 +- dev/Settings/Admin/Domains.js | 2 +- dev/Settings/User/Accounts.js | 8 ++--- dev/Settings/User/Filters.js | 2 +- dev/Settings/User/Folders.js | 4 +-- dev/Settings/User/OpenPgp.js | 3 -- dev/Stores/Admin/Domain.js | 2 +- dev/Stores/User/Pgp.js | 35 ++++++++++++------- dev/View/Popup/OpenPgpGenerate.js | 4 +-- dev/View/Popup/SieveScript.js | 2 +- .../Views/Admin/AdminSettingsDomains.html | 4 +-- .../Views/User/PopupsSieveScript.html | 4 +-- .../Views/User/SettingsAccounts.html | 8 ++--- .../templates/Views/User/SettingsFilters.html | 4 +-- .../Views/User/SettingsFolderItem.html | 4 +-- .../templates/Views/User/SettingsOpenPGP.html | 8 ++--- 21 files changed, 57 insertions(+), 51 deletions(-) diff --git a/dev/External/ko.js b/dev/External/ko.js index 02b3af11b..ec3bcec10 100644 --- a/dev/External/ko.js +++ b/dev/External/ko.js @@ -181,6 +181,6 @@ ko.extenders.falseTimeout = (target, option) => { // functions -ko.observable.fn.deleteAccessHelper = function() { - return this.extend({ falseTimeout: 3000, toggleSubscribeProperty: [this, 'deleteAccess'] }); +ko.observable.fn.askDeleteHelper = function() { + return this.extend({ falseTimeout: 3000, toggleSubscribeProperty: [this, 'askDelete'] }); }; diff --git a/dev/Model/Account.js b/dev/Model/Account.js index 1bf005b41..adfc5feec 100644 --- a/dev/Model/Account.js +++ b/dev/Model/Account.js @@ -13,7 +13,7 @@ export class AccountModel extends AbstractModel { this.addObservables({ // count: count || 0, - deleteAccess: false, + askDelete: false, isAdditional: isAdditional }); } diff --git a/dev/Model/Filter.js b/dev/Model/Filter.js index 8a9e5a0e5..242c3223b 100644 --- a/dev/Model/Filter.js +++ b/dev/Model/Filter.js @@ -38,7 +38,7 @@ export class FilterModel extends AbstractModel { this.addObservables({ enabled: true, - deleteAccess: false, + askDelete: false, canBeDeleted: true, name: '', diff --git a/dev/Model/FolderCollection.js b/dev/Model/FolderCollection.js index f8a6d2115..5da86b31e 100644 --- a/dev/Model/FolderCollection.js +++ b/dev/Model/FolderCollection.js @@ -218,7 +218,7 @@ export class FolderModel extends AbstractModel { edited: false, subscribed: true, checkable: false, // Check for new messages - deleteAccess: false, + askDelete: false, nameForEdit: '', errorMsg: '', diff --git a/dev/Model/Identity.js b/dev/Model/Identity.js index 63daa343b..9e3e82649 100644 --- a/dev/Model/Identity.js +++ b/dev/Model/Identity.js @@ -21,7 +21,7 @@ export class IdentityModel extends AbstractModel { signature: '', signatureInsertBefore: false, - deleteAccess: false + askDelete: false }); this.canBeDeleted = koComputable(() => !!this.id()); diff --git a/dev/Model/SieveScript.js b/dev/Model/SieveScript.js index 620abfe86..7db1e79f1 100644 --- a/dev/Model/SieveScript.js +++ b/dev/Model/SieveScript.js @@ -270,7 +270,7 @@ export class SieveScriptModel extends AbstractModel exists: false, nameError: false, bodyError: false, - deleteAccess: false, + askDelete: false, canBeDeleted: true, hasChanges: false }); diff --git a/dev/Settings/Admin/Domains.js b/dev/Settings/Admin/Domains.js index 6eeb83606..c08d183cc 100644 --- a/dev/Settings/Admin/Domains.js +++ b/dev/Settings/Admin/Domains.js @@ -12,7 +12,7 @@ export class DomainsAdminSettings /*extends AbstractViewSettings*/ { constructor() { this.domains = DomainAdminStore; - this.domainForDeletion = ko.observable(null).deleteAccessHelper(); + this.domainForDeletion = ko.observable(null).askDeleteHelper(); } createDomain() { diff --git a/dev/Settings/User/Accounts.js b/dev/Settings/User/Accounts.js index 3863b7ba0..cbcdcf1ed 100644 --- a/dev/Settings/User/Accounts.js +++ b/dev/Settings/User/Accounts.js @@ -22,8 +22,8 @@ export class AccountsUserSettings /*extends AbstractViewSettings*/ { this.identities = IdentityUserStore; this.mainEmail = SettingsGet('MainEmail'); - this.accountForDeletion = ko.observable(null).deleteAccessHelper(); - this.identityForDeletion = ko.observable(null).deleteAccessHelper(); + this.accountForDeletion = ko.observable(null).askDeleteHelper(); + this.identityForDeletion = ko.observable(null).askDeleteHelper(); } addNewAccount() { @@ -49,7 +49,7 @@ export class AccountsUserSettings /*extends AbstractViewSettings*/ { * @returns {void} */ deleteAccount(accountToRemove) { - if (accountToRemove && accountToRemove.deleteAccess()) { + if (accountToRemove && accountToRemove.askDelete()) { this.accountForDeletion(null); if (accountToRemove) { this.accounts.remove((account) => accountToRemove === account); @@ -73,7 +73,7 @@ export class AccountsUserSettings /*extends AbstractViewSettings*/ { * @returns {void} */ deleteIdentity(identityToRemove) { - if (identityToRemove && identityToRemove.deleteAccess()) { + if (identityToRemove && identityToRemove.askDelete()) { this.identityForDeletion(null); if (identityToRemove) { diff --git a/dev/Settings/User/Filters.js b/dev/Settings/User/Filters.js index 1cab1d387..b0cd9e812 100644 --- a/dev/Settings/User/Filters.js +++ b/dev/Settings/User/Filters.js @@ -23,7 +23,7 @@ export class FiltersUserSettings /*extends AbstractViewSettings*/ { serverErrorDesc: '' }); - this.scriptForDeletion = ko.observable(null).deleteAccessHelper(); + this.scriptForDeletion = ko.observable(null).askDeleteHelper(); } setError(text) { diff --git a/dev/Settings/User/Folders.js b/dev/Settings/User/Folders.js index 7693f3c5b..351096e15 100644 --- a/dev/Settings/User/Folders.js +++ b/dev/Settings/User/Folders.js @@ -22,7 +22,7 @@ import { showScreenPopup } from 'Knoin/Knoin'; import { FolderCreatePopupView } from 'View/Popup/FolderCreate'; import { FolderSystemPopupView } from 'View/Popup/FolderSystem'; -const folderForDeletion = ko.observable(null).deleteAccessHelper(); +const folderForDeletion = ko.observable(null).askDeleteHelper(); export class FoldersUserSettings /*extends AbstractViewSettings*/ { constructor() { @@ -124,7 +124,7 @@ export class FoldersUserSettings /*extends AbstractViewSettings*/ { deleteFolder(folderToRemove) { if (folderToRemove && folderToRemove.canBeDeleted() - && folderToRemove.deleteAccess() + && folderToRemove.askDelete() ) { if (0 < folderToRemove.privateMessageCountAll()) { // FolderUserStore.folderListError(getNotification(Notification.CantDeleteNonEmptyFolder)); diff --git a/dev/Settings/User/OpenPgp.js b/dev/Settings/User/OpenPgp.js index f4d490113..73f18c5e4 100644 --- a/dev/Settings/User/OpenPgp.js +++ b/dev/Settings/User/OpenPgp.js @@ -1,5 +1,3 @@ -import ko from 'ko'; - import { PgpUserStore } from 'Stores/User/Pgp'; import { SettingsUserStore } from 'Stores/User/Settings'; @@ -19,7 +17,6 @@ export class OpenPgpUserSettings /*extends AbstractViewSettings*/ { this.openpgpkeysPublic = PgpUserStore.openpgpPublicKeys; this.openpgpkeysPrivate = PgpUserStore.openpgpPrivateKeys; - this.openPgpKeyForDeletion = ko.observable(null).deleteAccessHelper(); this.canOpenPGP = Settings.capa(Capa.OpenPGP); this.canGnuPG = Settings.capa(Capa.GnuPG); diff --git a/dev/Stores/Admin/Domain.js b/dev/Stores/Admin/Domain.js index 4d41f6c0e..195ff2b77 100644 --- a/dev/Stores/Admin/Domain.js +++ b/dev/Stores/Admin/Domain.js @@ -14,7 +14,7 @@ DomainAdminStore.fetch = () => { DomainAdminStore( data.Result.map(item => { item.disabled = ko.observable(item.disabled); - item.deleteAccess = ko.observable(false); + item.askDelete = ko.observable(false); return item; }) ); diff --git a/dev/Stores/User/Pgp.js b/dev/Stores/User/Pgp.js index 18773cebc..b3ab19b7a 100644 --- a/dev/Stores/User/Pgp.js +++ b/dev/Stores/User/Pgp.js @@ -43,6 +43,14 @@ const } } return keys; + }, + storeOpenPgpKeys = (keys, section) => { + let armoredKeys = keys.map(item => item.armor); + if (armoredKeys.length) { + storage.setItem(section, JSON.stringify(armoredKeys)); + } else { + storage.removeItem(section); + } }; class OpenPgpKeyModel { @@ -62,8 +70,8 @@ class OpenPgpKeyModel { this.can_sign = !!key.getSigningKey(); this.emails = aEmails; this.armor = armor; - this.deleteAccess = ko.observable(false); - this.openForDeletion = ko.observable(null).deleteAccessHelper(); + this.askDelete = ko.observable(false); + this.openForDeletion = ko.observable(null).askDeleteHelper(); // key.getUserIDs() // key.getPrimaryUser() } @@ -73,23 +81,15 @@ class OpenPgpKeyModel { } remove() { - if (this.deleteAccess()) { - this.openPgpKeyForDeletion(null); - let armoredKeys = [], itemname = publicKeysItem; + if (this.askDelete()) { if (this.key.isPrivate()) { - itemname = privateKeysItem; PgpUserStore.openpgpPrivateKeys.remove(this); - armoredKeys = PgpUserStore.openpgpPrivateKeys.map(item => item.armor); + storeOpenPgpKeys(PgpUserStore.openpgpPrivateKeys, privateKeysItem); } else { PgpUserStore.openpgpPublicKeys.remove(this); - armoredKeys = PgpUserStore.openpgpPublicKeys.map(item => item.armor); + storeOpenPgpKeys(PgpUserStore.openpgpPublicKeys, publicKeysItem); } delegateRunOnDestroy(this); - if (armoredKeys.length) { - storage.setItem(itemname, JSON.stringify(armoredKeys)); - } else { - storage.removeItem(itemname); - } } } } @@ -215,6 +215,15 @@ export const PgpUserStore = new class { ); // storeKeys(publicKeysItem); // storeKeys(privateKeysItem); + + openpgp.readKey({armoredKey:keyPair.publicKey}).then(key => { + PgpUserStore.openpgpPublicKeys.push(new OpenPgpKeyModel(keyPair.publicKey, key)); + storeOpenPgpKeys(PgpUserStore.openpgpPublicKeys, publicKeysItem); + }); + openpgp.readKey({armoredKey:keyPair.privateKey}).then(key => { + PgpUserStore.openpgpPrivateKeys.push(new OpenPgpKeyModel(keyPair.privateKey, key)); + storeOpenPgpKeys(PgpUserStore.openpgpPrivateKeys, privateKeysItem); + }); } /** diff --git a/dev/View/Popup/OpenPgpGenerate.js b/dev/View/Popup/OpenPgpGenerate.js index 5cacc0050..fd66c7a75 100644 --- a/dev/View/Popup/OpenPgpGenerate.js +++ b/dev/View/Popup/OpenPgpGenerate.js @@ -68,8 +68,8 @@ export class OpenPgpGeneratePopupView extends AbstractViewPopup { openpgp.generateKey(cfg).then(keyPair => { if (keyPair) { - keyPair.onServer = !!this.saveServer(); - keyPair.inGnuPG = !!this.saveGnuPG(); + keyPair.onServer = this.saveServer() ? 1 : 0; + keyPair.inGnuPG = this.saveGnuPG() ? 1 : 0; keyPair.uid = userId; PgpUserStore.storeKeyPair(keyPair, ()=>{ this.submitRequest(false); diff --git a/dev/View/Popup/SieveScript.js b/dev/View/Popup/SieveScript.js index 33f7ddcb4..a408fab49 100644 --- a/dev/View/Popup/SieveScript.js +++ b/dev/View/Popup/SieveScript.js @@ -28,7 +28,7 @@ class SieveScriptPopupView extends AbstractViewPopup { this.sieveCapabilities = SieveUserStore.capa.join(' '); this.saving = false; - this.filterForDeletion = ko.observable(null).deleteAccessHelper(); + this.filterForDeletion = ko.observable(null).askDeleteHelper(); /* decorateKoCommands(this, { saveScriptCommand: 1 diff --git a/snappymail/v/0.0.0/app/templates/Views/Admin/AdminSettingsDomains.html b/snappymail/v/0.0.0/app/templates/Views/Admin/AdminSettingsDomains.html index 97008cbfb..869c7f70f 100644 --- a/snappymail/v/0.0.0/app/templates/Views/Admin/AdminSettingsDomains.html +++ b/snappymail/v/0.0.0/app/templates/Views/Admin/AdminSettingsDomains.html @@ -30,11 +30,11 @@ (alias)