mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 13:58:50 +08:00
fix: revoke permission if failed to send email (#4279)
This commit is contained in:
@@ -205,7 +205,7 @@ export interface AFFiNEConfig {
|
|||||||
ttl: number;
|
ttl: number;
|
||||||
/**
|
/**
|
||||||
* How many requests can be made in the given time frame
|
* How many requests can be made in the given time frame
|
||||||
* @default 60
|
* @default 120
|
||||||
* @env THROTTLE_LIMIT
|
* @env THROTTLE_LIMIT
|
||||||
*/
|
*/
|
||||||
limit: number;
|
limit: number;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { Storage } from '@affine/storage';
|
|||||||
import {
|
import {
|
||||||
ForbiddenException,
|
ForbiddenException,
|
||||||
Inject,
|
Inject,
|
||||||
|
InternalServerErrorException,
|
||||||
Logger,
|
Logger,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
@@ -426,17 +427,33 @@ export class WorkspaceResolver {
|
|||||||
if (sendInviteMail) {
|
if (sendInviteMail) {
|
||||||
const inviteInfo = await this.getInviteInfo(inviteId);
|
const inviteInfo = await this.getInviteInfo(inviteId);
|
||||||
|
|
||||||
await this.mailer.sendInviteEmail(email, inviteId, {
|
try {
|
||||||
workspace: {
|
await this.mailer.sendInviteEmail(email, inviteId, {
|
||||||
id: inviteInfo.workspace.id,
|
workspace: {
|
||||||
name: inviteInfo.workspace.name,
|
id: inviteInfo.workspace.id,
|
||||||
avatar: inviteInfo.workspace.avatar,
|
name: inviteInfo.workspace.name,
|
||||||
},
|
avatar: inviteInfo.workspace.avatar,
|
||||||
user: {
|
},
|
||||||
avatar: inviteInfo.user?.avatarUrl || '',
|
user: {
|
||||||
name: inviteInfo.user?.name || '',
|
avatar: inviteInfo.user?.avatarUrl || '',
|
||||||
},
|
name: inviteInfo.user?.name || '',
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
const ret = await this.permissions.revoke(workspaceId, target.id);
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
this.logger.fatal(
|
||||||
|
`failed to send ${workspaceId} invite email to ${email} and failed to revoke permission: ${inviteId}, ${e}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.logger.warn(
|
||||||
|
`failed to send ${workspaceId} invite email to ${email}, but successfully revoked permission: ${e}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new InternalServerErrorException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return inviteId;
|
return inviteId;
|
||||||
} else {
|
} else {
|
||||||
@@ -449,17 +466,33 @@ export class WorkspaceResolver {
|
|||||||
if (sendInviteMail) {
|
if (sendInviteMail) {
|
||||||
const inviteInfo = await this.getInviteInfo(inviteId);
|
const inviteInfo = await this.getInviteInfo(inviteId);
|
||||||
|
|
||||||
await this.mailer.sendInviteEmail(email, inviteId, {
|
try {
|
||||||
workspace: {
|
await this.mailer.sendInviteEmail(email, inviteId, {
|
||||||
id: inviteInfo.workspace.id,
|
workspace: {
|
||||||
name: inviteInfo.workspace.name,
|
id: inviteInfo.workspace.id,
|
||||||
avatar: inviteInfo.workspace.avatar,
|
name: inviteInfo.workspace.name,
|
||||||
},
|
avatar: inviteInfo.workspace.avatar,
|
||||||
user: {
|
},
|
||||||
avatar: inviteInfo.user?.avatarUrl || '',
|
user: {
|
||||||
name: inviteInfo.user?.name || '',
|
avatar: inviteInfo.user?.avatarUrl || '',
|
||||||
},
|
name: inviteInfo.user?.name || '',
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
const ret = await this.permissions.revoke(workspaceId, user.id);
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
this.logger.fatal(
|
||||||
|
`failed to send ${workspaceId} invite email to ${email} and failed to revoke permission: ${inviteId}, ${e}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.logger.warn(
|
||||||
|
`failed to send ${workspaceId} invite email to ${email}, but successfully revoked permission: ${e}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new InternalServerErrorException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return inviteId;
|
return inviteId;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user