OpenPGP.js now stores keys in localStorage

Renamed all deleteAccess to askDelete
This commit is contained in:
the-djmaze 2022-01-27 23:07:34 +01:00
parent 9ab72e7a34
commit 0da681f074
21 changed files with 57 additions and 51 deletions

4
dev/External/ko.js vendored
View file

@ -181,6 +181,6 @@ ko.extenders.falseTimeout = (target, option) => {
// functions // functions
ko.observable.fn.deleteAccessHelper = function() { ko.observable.fn.askDeleteHelper = function() {
return this.extend({ falseTimeout: 3000, toggleSubscribeProperty: [this, 'deleteAccess'] }); return this.extend({ falseTimeout: 3000, toggleSubscribeProperty: [this, 'askDelete'] });
}; };

View file

@ -13,7 +13,7 @@ export class AccountModel extends AbstractModel {
this.addObservables({ this.addObservables({
// count: count || 0, // count: count || 0,
deleteAccess: false, askDelete: false,
isAdditional: isAdditional isAdditional: isAdditional
}); });
} }

View file

@ -38,7 +38,7 @@ export class FilterModel extends AbstractModel {
this.addObservables({ this.addObservables({
enabled: true, enabled: true,
deleteAccess: false, askDelete: false,
canBeDeleted: true, canBeDeleted: true,
name: '', name: '',

View file

@ -218,7 +218,7 @@ export class FolderModel extends AbstractModel {
edited: false, edited: false,
subscribed: true, subscribed: true,
checkable: false, // Check for new messages checkable: false, // Check for new messages
deleteAccess: false, askDelete: false,
nameForEdit: '', nameForEdit: '',
errorMsg: '', errorMsg: '',

View file

@ -21,7 +21,7 @@ export class IdentityModel extends AbstractModel {
signature: '', signature: '',
signatureInsertBefore: false, signatureInsertBefore: false,
deleteAccess: false askDelete: false
}); });
this.canBeDeleted = koComputable(() => !!this.id()); this.canBeDeleted = koComputable(() => !!this.id());

View file

@ -270,7 +270,7 @@ export class SieveScriptModel extends AbstractModel
exists: false, exists: false,
nameError: false, nameError: false,
bodyError: false, bodyError: false,
deleteAccess: false, askDelete: false,
canBeDeleted: true, canBeDeleted: true,
hasChanges: false hasChanges: false
}); });

View file

@ -12,7 +12,7 @@ export class DomainsAdminSettings /*extends AbstractViewSettings*/ {
constructor() { constructor() {
this.domains = DomainAdminStore; this.domains = DomainAdminStore;
this.domainForDeletion = ko.observable(null).deleteAccessHelper(); this.domainForDeletion = ko.observable(null).askDeleteHelper();
} }
createDomain() { createDomain() {

View file

@ -22,8 +22,8 @@ export class AccountsUserSettings /*extends AbstractViewSettings*/ {
this.identities = IdentityUserStore; this.identities = IdentityUserStore;
this.mainEmail = SettingsGet('MainEmail'); this.mainEmail = SettingsGet('MainEmail');
this.accountForDeletion = ko.observable(null).deleteAccessHelper(); this.accountForDeletion = ko.observable(null).askDeleteHelper();
this.identityForDeletion = ko.observable(null).deleteAccessHelper(); this.identityForDeletion = ko.observable(null).askDeleteHelper();
} }
addNewAccount() { addNewAccount() {
@ -49,7 +49,7 @@ export class AccountsUserSettings /*extends AbstractViewSettings*/ {
* @returns {void} * @returns {void}
*/ */
deleteAccount(accountToRemove) { deleteAccount(accountToRemove) {
if (accountToRemove && accountToRemove.deleteAccess()) { if (accountToRemove && accountToRemove.askDelete()) {
this.accountForDeletion(null); this.accountForDeletion(null);
if (accountToRemove) { if (accountToRemove) {
this.accounts.remove((account) => accountToRemove === account); this.accounts.remove((account) => accountToRemove === account);
@ -73,7 +73,7 @@ export class AccountsUserSettings /*extends AbstractViewSettings*/ {
* @returns {void} * @returns {void}
*/ */
deleteIdentity(identityToRemove) { deleteIdentity(identityToRemove) {
if (identityToRemove && identityToRemove.deleteAccess()) { if (identityToRemove && identityToRemove.askDelete()) {
this.identityForDeletion(null); this.identityForDeletion(null);
if (identityToRemove) { if (identityToRemove) {

View file

@ -23,7 +23,7 @@ export class FiltersUserSettings /*extends AbstractViewSettings*/ {
serverErrorDesc: '' serverErrorDesc: ''
}); });
this.scriptForDeletion = ko.observable(null).deleteAccessHelper(); this.scriptForDeletion = ko.observable(null).askDeleteHelper();
} }
setError(text) { setError(text) {

View file

@ -22,7 +22,7 @@ import { showScreenPopup } from 'Knoin/Knoin';
import { FolderCreatePopupView } from 'View/Popup/FolderCreate'; import { FolderCreatePopupView } from 'View/Popup/FolderCreate';
import { FolderSystemPopupView } from 'View/Popup/FolderSystem'; import { FolderSystemPopupView } from 'View/Popup/FolderSystem';
const folderForDeletion = ko.observable(null).deleteAccessHelper(); const folderForDeletion = ko.observable(null).askDeleteHelper();
export class FoldersUserSettings /*extends AbstractViewSettings*/ { export class FoldersUserSettings /*extends AbstractViewSettings*/ {
constructor() { constructor() {
@ -124,7 +124,7 @@ export class FoldersUserSettings /*extends AbstractViewSettings*/ {
deleteFolder(folderToRemove) { deleteFolder(folderToRemove) {
if (folderToRemove if (folderToRemove
&& folderToRemove.canBeDeleted() && folderToRemove.canBeDeleted()
&& folderToRemove.deleteAccess() && folderToRemove.askDelete()
) { ) {
if (0 < folderToRemove.privateMessageCountAll()) { if (0 < folderToRemove.privateMessageCountAll()) {
// FolderUserStore.folderListError(getNotification(Notification.CantDeleteNonEmptyFolder)); // FolderUserStore.folderListError(getNotification(Notification.CantDeleteNonEmptyFolder));

View file

@ -1,5 +1,3 @@
import ko from 'ko';
import { PgpUserStore } from 'Stores/User/Pgp'; import { PgpUserStore } from 'Stores/User/Pgp';
import { SettingsUserStore } from 'Stores/User/Settings'; import { SettingsUserStore } from 'Stores/User/Settings';
@ -19,7 +17,6 @@ export class OpenPgpUserSettings /*extends AbstractViewSettings*/ {
this.openpgpkeysPublic = PgpUserStore.openpgpPublicKeys; this.openpgpkeysPublic = PgpUserStore.openpgpPublicKeys;
this.openpgpkeysPrivate = PgpUserStore.openpgpPrivateKeys; this.openpgpkeysPrivate = PgpUserStore.openpgpPrivateKeys;
this.openPgpKeyForDeletion = ko.observable(null).deleteAccessHelper();
this.canOpenPGP = Settings.capa(Capa.OpenPGP); this.canOpenPGP = Settings.capa(Capa.OpenPGP);
this.canGnuPG = Settings.capa(Capa.GnuPG); this.canGnuPG = Settings.capa(Capa.GnuPG);

View file

@ -14,7 +14,7 @@ DomainAdminStore.fetch = () => {
DomainAdminStore( DomainAdminStore(
data.Result.map(item => { data.Result.map(item => {
item.disabled = ko.observable(item.disabled); item.disabled = ko.observable(item.disabled);
item.deleteAccess = ko.observable(false); item.askDelete = ko.observable(false);
return item; return item;
}) })
); );

View file

@ -43,6 +43,14 @@ const
} }
} }
return keys; 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 { class OpenPgpKeyModel {
@ -62,8 +70,8 @@ class OpenPgpKeyModel {
this.can_sign = !!key.getSigningKey(); this.can_sign = !!key.getSigningKey();
this.emails = aEmails; this.emails = aEmails;
this.armor = armor; this.armor = armor;
this.deleteAccess = ko.observable(false); this.askDelete = ko.observable(false);
this.openForDeletion = ko.observable(null).deleteAccessHelper(); this.openForDeletion = ko.observable(null).askDeleteHelper();
// key.getUserIDs() // key.getUserIDs()
// key.getPrimaryUser() // key.getPrimaryUser()
} }
@ -73,23 +81,15 @@ class OpenPgpKeyModel {
} }
remove() { remove() {
if (this.deleteAccess()) { if (this.askDelete()) {
this.openPgpKeyForDeletion(null);
let armoredKeys = [], itemname = publicKeysItem;
if (this.key.isPrivate()) { if (this.key.isPrivate()) {
itemname = privateKeysItem;
PgpUserStore.openpgpPrivateKeys.remove(this); PgpUserStore.openpgpPrivateKeys.remove(this);
armoredKeys = PgpUserStore.openpgpPrivateKeys.map(item => item.armor); storeOpenPgpKeys(PgpUserStore.openpgpPrivateKeys, privateKeysItem);
} else { } else {
PgpUserStore.openpgpPublicKeys.remove(this); PgpUserStore.openpgpPublicKeys.remove(this);
armoredKeys = PgpUserStore.openpgpPublicKeys.map(item => item.armor); storeOpenPgpKeys(PgpUserStore.openpgpPublicKeys, publicKeysItem);
} }
delegateRunOnDestroy(this); 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(publicKeysItem);
// storeKeys(privateKeysItem); // 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);
});
} }
/** /**

View file

@ -68,8 +68,8 @@ export class OpenPgpGeneratePopupView extends AbstractViewPopup {
openpgp.generateKey(cfg).then(keyPair => { openpgp.generateKey(cfg).then(keyPair => {
if (keyPair) { if (keyPair) {
keyPair.onServer = !!this.saveServer(); keyPair.onServer = this.saveServer() ? 1 : 0;
keyPair.inGnuPG = !!this.saveGnuPG(); keyPair.inGnuPG = this.saveGnuPG() ? 1 : 0;
keyPair.uid = userId; keyPair.uid = userId;
PgpUserStore.storeKeyPair(keyPair, ()=>{ PgpUserStore.storeKeyPair(keyPair, ()=>{
this.submitRequest(false); this.submitRequest(false);

View file

@ -28,7 +28,7 @@ class SieveScriptPopupView extends AbstractViewPopup {
this.sieveCapabilities = SieveUserStore.capa.join(' '); this.sieveCapabilities = SieveUserStore.capa.join(' ');
this.saving = false; this.saving = false;
this.filterForDeletion = ko.observable(null).deleteAccessHelper(); this.filterForDeletion = ko.observable(null).askDeleteHelper();
/* /*
decorateKoCommands(this, { decorateKoCommands(this, {
saveScriptCommand: 1 saveScriptCommand: 1

View file

@ -30,11 +30,11 @@
<span class="domain-alias" data-bind="if: alias">(alias)</span> <span class="domain-alias" data-bind="if: alias">(alias)</span>
</td> </td>
<td> <td>
<a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': deleteAccess()}, click: function(oDomain) { $root.deleteDomain(oDomain); }" <a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': askDelete()}, click: function(oDomain) { $root.deleteDomain(oDomain); }"
data-i18n="TAB_DOMAINS/DELETE_ARE_YOU_SURE"></a> data-i18n="TAB_DOMAINS/DELETE_ARE_YOU_SURE"></a>
</td> </td>
<td> <td>
<span class="delete-domain fontastic" data-bind="visible: !deleteAccess(), click: function (oDomain) { $root.domainForDeletion(oDomain); }">🗑</span> <span class="delete-domain fontastic" data-bind="visible: !askDelete(), click: function (oDomain) { $root.domainForDeletion(oDomain); }">🗑</span>
</td> </td>
<td class="disabled-domain fontastic" data-bind="click: function (oDomain) { $root.disableDomain(oDomain); }, text: disabled() ? '☐' : '☑'"></td> <td class="disabled-domain fontastic" data-bind="click: function (oDomain) { $root.disableDomain(oDomain); }, text: disabled() ? '☐' : '☑'"></td>
</tr> </tr>

View file

@ -55,11 +55,11 @@
<span class="filter-sub-name" data-bind="text: nameSub()"></span> <span class="filter-sub-name" data-bind="text: nameSub()"></span>
</td> </td>
<td> <td>
<a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': deleteAccess()}, click: function(oFilter) { $root.deleteFilter(oFilter); }" <a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': askDelete()}, click: function(oFilter) { $root.deleteFilter(oFilter); }"
data-i18n="GLOBAL/ARE_YOU_SURE"></a> data-i18n="GLOBAL/ARE_YOU_SURE"></a>
</td> </td>
<td> <td>
<span class="delete-filter fontastic" data-bind="visible: !deleteAccess() && canBeDeleted(), click: function (oFilter) { $root.filterForDeletion(oFilter); }">🗑</span> <span class="delete-filter fontastic" data-bind="visible: !askDelete() && canBeDeleted(), click: function (oFilter) { $root.filterForDeletion(oFilter); }">🗑</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View file

@ -23,11 +23,11 @@
<span class="account-name" data-bind="text: email"></span> <span class="account-name" data-bind="text: email"></span>
</td> </td>
<td> <td>
<a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': deleteAccess}, click: function(oAccount) { $root.deleteAccount(oAccount); }" <a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': askDelete}, click: function(oAccount) { $root.deleteAccount(oAccount); }"
data-i18n="GLOBAL/ARE_YOU_SURE"></a> data-i18n="GLOBAL/ARE_YOU_SURE"></a>
</td> </td>
<td> <td>
<span class="delete fontastic" data-bind="visible: !deleteAccess(), click: function (oAccount) { $root.accountForDeletion(oAccount); }">🗑</span> <span class="delete fontastic" data-bind="visible: !askDelete(), click: function (oAccount) { $root.accountForDeletion(oAccount); }">🗑</span>
</td> </td>
</tr> </tr>
<!-- /ko --> <!-- /ko -->
@ -52,11 +52,11 @@
<span class="identity-default" data-bind="visible: 0 === $index()" data-i18n="SETTINGS_ACCOUNTS/DEFAULT_IDENTITY_LABEL"></span> <span class="identity-default" data-bind="visible: 0 === $index()" data-i18n="SETTINGS_ACCOUNTS/DEFAULT_IDENTITY_LABEL"></span>
</td> </td>
<td> <td>
<a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="visible: canBeDeleted, css: {'delete-access': deleteAccess}, click: function(oIdentity) { $root.deleteIdentity(oIdentity); }" <a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="visible: canBeDeleted, css: {'delete-access': askDelete}, click: function(oIdentity) { $root.deleteIdentity(oIdentity); }"
data-i18n="GLOBAL/ARE_YOU_SURE"></a> data-i18n="GLOBAL/ARE_YOU_SURE"></a>
</td> </td>
<td> <td>
<span class="delete fontastic" data-bind="visible: !deleteAccess() && canBeDeleted(), click: function (oIdentity) { $root.identityForDeletion(oIdentity); }">🗑</span> <span class="delete fontastic" data-bind="visible: !askDelete() && canBeDeleted(), click: function (oIdentity) { $root.identityForDeletion(oIdentity); }">🗑</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View file

@ -24,11 +24,11 @@
</td> </td>
<td class="e-action" class="script-name" data-bind="text: name()"></td> <td class="e-action" class="script-name" data-bind="text: name()"></td>
<td> <td>
<a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': deleteAccess()}, click: function(oScript) { $root.deleteScript(oScript); }" <a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': askDelete()}, click: function(oScript) { $root.deleteScript(oScript); }"
data-i18n="GLOBAL/ARE_YOU_SURE"></a> data-i18n="GLOBAL/ARE_YOU_SURE"></a>
</td> </td>
<td> <td>
<span class="delete-script fontastic" data-bind="visible: !deleteAccess() && canBeDeleted(), click: function (oScript) { $root.scriptForDeletion(oScript); }">🗑</span> <span class="delete-script fontastic" data-bind="visible: !askDelete() && canBeDeleted(), click: function (oScript) { $root.scriptForDeletion(oScript); }">🗑</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View file

@ -10,9 +10,9 @@
<span class="folder-system-name" data-bind="text: manageFolderSystemName, visible: isSystemFolder"></span> <span class="folder-system-name" data-bind="text: manageFolderSystemName, visible: isSystemFolder"></span>
</td> </td>
<td data-i18n="[title]SETTINGS_FOLDERS/HELP_DELETE_FOLDER"> <td data-i18n="[title]SETTINGS_FOLDERS/HELP_DELETE_FOLDER">
<a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': deleteAccess()}, click: $root.deleteFolder" <a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': askDelete()}, click: $root.deleteFolder"
data-i18n="GLOBAL/ARE_YOU_SURE"></a> data-i18n="GLOBAL/ARE_YOU_SURE"></a>
<span class="delete-folder e-action fontastic" data-bind="visible: canBeDeleted() && !deleteAccess(), click: $root.folderForDeletion">🗑</span> <span class="delete-folder e-action fontastic" data-bind="visible: canBeDeleted() && !askDelete(), click: $root.folderForDeletion">🗑</span>
</td> </td>
<td data-i18n="[title]SETTINGS_FOLDERS/HELP_SHOW_HIDE_FOLDER"> <td data-i18n="[title]SETTINGS_FOLDERS/HELP_SHOW_HIDE_FOLDER">
<span class="e-action fontastic" data-bind="css: {'unsubscribed-folder':!subscribed()}, visible: canBeSubscribed(), click: $root.toggleFolderSubscription">👁</span> <span class="e-action fontastic" data-bind="css: {'unsubscribed-folder':!subscribed()}, visible: canBeSubscribed(), click: $root.toggleFolderSubscription">👁</span>

View file

@ -55,11 +55,11 @@
<!-- /ko --> <!-- /ko -->
</td> </td>
<td> <td>
<a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': deleteAccess()}, click: remove" <a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': askDelete()}, click: remove"
data-i18n="GLOBAL/ARE_YOU_SURE"></a> data-i18n="GLOBAL/ARE_YOU_SURE"></a>
</td> </td>
<td> <td>
<span class="delete-open-pgp-key fontastic" data-bind="visible: !deleteAccess(), click: openForDeletion">🗑</span> <span class="delete-open-pgp-key fontastic" data-bind="visible: !askDelete(), click: openForDeletion">🗑</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -73,11 +73,11 @@
<!-- /ko --> <!-- /ko -->
</td> </td>
<td> <td>
<a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': deleteAccess()}, click: remove" <a class="btn btn-small btn-small-small btn-danger button-confirm-delete" data-bind="css: {'delete-access': askDelete()}, click: remove"
data-i18n="GLOBAL/ARE_YOU_SURE"></a> data-i18n="GLOBAL/ARE_YOU_SURE"></a>
</td> </td>
<td> <td>
<span class="delete-open-pgp-key fontastic" data-bind="visible: !deleteAccess(), click: openForDeletion">🗑</span> <span class="delete-open-pgp-key fontastic" data-bind="visible: !askDelete(), click: openForDeletion">🗑</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>