Skip to content

Commit 19c60a5

Browse files
committed
[IMP] vault: Don't require keys on service load to avoid annoying notifications
1 parent c3b2746 commit 19c60a5

2 files changed

Lines changed: 32 additions & 45 deletions

File tree

vault/static/src/backend/controller.esm.js

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,37 +71,42 @@ patch(FormController.prototype, {
7171
* @private
7272
*/
7373
async _newVaultKeyPair() {
74-
// Get the current private key
75-
const private_key = await this.vault.get_private_key();
76-
77-
// Generate new keys
78-
await this.vault.generate_keys();
79-
80-
const public_key = await this.vault.get_public_key();
74+
this.uuid = await this.vault._check_database();
75+
if (this.uuid) {
76+
// The user has a private key so get it
77+
const private_key = await this.vault.get_private_key();
78+
79+
// Generate new keys
80+
await this.vault.generate_keys();
81+
82+
const public_key = await this.vault.get_public_key();
83+
84+
// Re-encrypt the master keys
85+
const master_keys = await rpc("/vault/rights/get");
86+
let result = {};
87+
for (const uuid in master_keys) {
88+
result[uuid] = await this.vault_utils.wrap(
89+
await this.vault_utils.unwrap(master_keys[uuid], private_key),
90+
public_key
91+
);
92+
}
8193

82-
// Re-encrypt the master keys
83-
const master_keys = await rpc("/vault/rights/get");
84-
let result = {};
85-
for (const uuid in master_keys) {
86-
result[uuid] = await this.vault_utils.wrap(
87-
await this.vault_utils.unwrap(master_keys[uuid], private_key),
88-
public_key
89-
);
90-
}
94+
await rpc("/vault/rights/store", {keys: result});
9195

92-
await rpc("/vault/rights/store", {keys: result});
96+
// Re-encrypt the inboxes to not loose it
97+
const inbox_keys = await rpc("/vault/inbox/get");
98+
result = {};
99+
for (const uuid in inbox_keys) {
100+
result[uuid] = await this.vault_utils.wrap(
101+
await this.vault_utils.unwrap(inbox_keys[uuid], private_key),
102+
public_key
103+
);
104+
}
93105

94-
// Re-encrypt the inboxes to not loose it
95-
const inbox_keys = await rpc("/vault/inbox/get");
96-
result = {};
97-
for (const uuid in inbox_keys) {
98-
result[uuid] = await this.vault_utils.wrap(
99-
await this.vault_utils.unwrap(inbox_keys[uuid], private_key),
100-
public_key
101-
);
106+
await rpc("/vault/inbox/store", {keys: result});
107+
} else {
108+
await this.vault._initialize_keys();
102109
}
103-
104-
await rpc("/vault/inbox/store", {keys: result});
105110
},
106111

107112
/**

vault/static/src/backend/vault.esm.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,6 @@ const vaultService = {
4444
}
4545

4646
class Vault {
47-
/**
48-
* Check if the user actually has keys otherwise generate them on init
49-
*
50-
* @override
51-
*/
52-
constructor() {
53-
const self = this;
54-
55-
function waitAndCheck() {
56-
if (!vault_utils.supported()) return null;
57-
58-
if (odoo.isReady) self._initialize_keys();
59-
else setTimeout(waitAndCheck, 500);
60-
}
61-
62-
setTimeout(waitAndCheck, 500);
63-
}
64-
6547
/**
6648
* Generate a new key pair and export to database and object store
6749
*/

0 commit comments

Comments
 (0)