mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-29 11:01:34 +08:00
OpenPGP.js now stores keys in localStorage
Renamed all deleteAccess to askDelete
This commit is contained in:
parent
9ab72e7a34
commit
0da681f074
21 changed files with 57 additions and 51 deletions
4
dev/External/ko.js
vendored
4
dev/External/ko.js
vendored
|
@ -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'] });
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ export class AccountModel extends AbstractModel {
|
|||
|
||||
this.addObservables({
|
||||
// count: count || 0,
|
||||
deleteAccess: false,
|
||||
askDelete: false,
|
||||
isAdditional: isAdditional
|
||||
});
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ export class FilterModel extends AbstractModel {
|
|||
|
||||
this.addObservables({
|
||||
enabled: true,
|
||||
deleteAccess: false,
|
||||
askDelete: false,
|
||||
canBeDeleted: true,
|
||||
|
||||
name: '',
|
||||
|
|
|
@ -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: '',
|
||||
|
|
|
@ -21,7 +21,7 @@ export class IdentityModel extends AbstractModel {
|
|||
signature: '',
|
||||
signatureInsertBefore: false,
|
||||
|
||||
deleteAccess: false
|
||||
askDelete: false
|
||||
});
|
||||
|
||||
this.canBeDeleted = koComputable(() => !!this.id());
|
||||
|
|
|
@ -270,7 +270,7 @@ export class SieveScriptModel extends AbstractModel
|
|||
exists: false,
|
||||
nameError: false,
|
||||
bodyError: false,
|
||||
deleteAccess: false,
|
||||
askDelete: false,
|
||||
canBeDeleted: true,
|
||||
hasChanges: false
|
||||
});
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -23,7 +23,7 @@ export class FiltersUserSettings /*extends AbstractViewSettings*/ {
|
|||
serverErrorDesc: ''
|
||||
});
|
||||
|
||||
this.scriptForDeletion = ko.observable(null).deleteAccessHelper();
|
||||
this.scriptForDeletion = ko.observable(null).askDeleteHelper();
|
||||
}
|
||||
|
||||
setError(text) {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
})
|
||||
);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -30,11 +30,11 @@
|
|||
<span class="domain-alias" data-bind="if: alias">(alias)</span>
|
||||
</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>
|
||||
</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 class="disabled-domain fontastic" data-bind="click: function (oDomain) { $root.disableDomain(oDomain); }, text: disabled() ? '☐' : '☑'"></td>
|
||||
</tr>
|
||||
|
|
|
@ -55,11 +55,11 @@
|
|||
<span class="filter-sub-name" data-bind="text: nameSub()"></span>
|
||||
</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>
|
||||
</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>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -23,11 +23,11 @@
|
|||
<span class="account-name" data-bind="text: email"></span>
|
||||
</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>
|
||||
</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>
|
||||
</tr>
|
||||
<!-- /ko -->
|
||||
|
@ -52,11 +52,11 @@
|
|||
<span class="identity-default" data-bind="visible: 0 === $index()" data-i18n="SETTINGS_ACCOUNTS/DEFAULT_IDENTITY_LABEL"></span>
|
||||
</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>
|
||||
</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>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -24,11 +24,11 @@
|
|||
</td>
|
||||
<td class="e-action" class="script-name" data-bind="text: name()"></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>
|
||||
</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>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
<span class="folder-system-name" data-bind="text: manageFolderSystemName, visible: isSystemFolder"></span>
|
||||
</td>
|
||||
<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>
|
||||
<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 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>
|
||||
|
|
|
@ -55,11 +55,11 @@
|
|||
<!-- /ko -->
|
||||
</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>
|
||||
</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>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -73,11 +73,11 @@
|
|||
<!-- /ko -->
|
||||
</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>
|
||||
</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>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in a new issue