Skip to content

Commit a00b07e

Browse files
xabg2jzunigax2
authored andcommitted
feat: suspend account correctly by using Merge type
1 parent 1641fe8 commit a00b07e

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ STALWART_SMTP_PORT=587
2222
# Auth
2323
JWT_SECRET=
2424
GATEWAY_PUBLIC_SECRET=
25+
GATEWAY_PRIVATE_SECRET=
2526

2627
# External APIs
2728
PAYMENTS_API_URL=

src/modules/infrastructure/stalwart/stalwart.service.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const TYPE_USER = 'User';
3333
const TYPE_PASSWORD = 'Password';
3434
const CREATE_REF = 'new1';
3535

36-
const SUSPEND_PERMISSIONS = ['email-receive', 'email-send'] as const;
36+
const SUSPEND_PERMISSIONS = ['emailReceive', 'emailSend'] as const;
3737

3838
export interface StalwartAccountCreate {
3939
name: string;
@@ -205,16 +205,34 @@ export class StalwartService implements OnModuleInit, OnModuleDestroy {
205205
throw new StalwartApiError(`Account '${email}' not found`, null);
206206
}
207207

208-
const value = suspended ? true : null;
209-
const patch = Object.fromEntries(
210-
SUSPEND_PERMISSIONS.map((p) => [`disabledPermissions/${p}`, value]),
208+
const disabledPermissions = Object.fromEntries(
209+
SUSPEND_PERMISSIONS.map((p) => [p, true]),
211210
);
211+
const permissions = suspended
212+
? {
213+
'@type': 'Merge',
214+
enabledPermissions: {},
215+
disabledPermissions,
216+
}
217+
: { '@type': 'Inherit' };
212218

213219
const response = await this.jmapCall<JmapSetResponse<StalwartAccount>>([
214-
[JMAP_METHOD.ACCOUNT_SET, { update: { [account.id]: patch } }, 's1'],
220+
[
221+
JMAP_METHOD.ACCOUNT_SET,
222+
{
223+
update: {
224+
[account.id]: {
225+
permissions,
226+
},
227+
},
228+
},
229+
's1',
230+
],
215231
]);
216232
const set = firstResponse(response);
217233

234+
this.logger.debug(`[DEBUG] x:Account/set response: ${JSON.stringify(set)}`);
235+
218236
const failed = set.notUpdated?.[account.id];
219237
if (failed) {
220238
throw new StalwartApiError(

0 commit comments

Comments
 (0)