There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
fix: revoke permission if failed to send email (#4279)
DarkSkyb261d97ed22a
diff --git a/apps/server/src/config/def.ts b/apps/server/src/config/def.tsindex efe6b0b297..c72c302d6c 100644--- a/apps/server/src/config/def.ts+++ b/apps/server/src/config/def.ts@@ -205,7 +205,7 @@ export interface AFFiNEConfig {ttl: number;/*** How many requests can be made in the given time frame- * @default 60+ * @default 120* @env THROTTLE_LIMIT*/limit: number;diff --git a/apps/server/src/modules/workspaces/resolver.ts b/apps/server/src/modules/workspaces/resolver.tsindex b5937ab7ab..bd639952e4 100644--- a/apps/server/src/modules/workspaces/resolver.ts+++ b/apps/server/src/modules/workspaces/resolver.ts@@ -2,6 +2,7 @@ import type { Storage } from '@affine/storage';import {ForbiddenException,Inject,+ InternalServerErrorException,Logger,NotFoundException,UseGuards,@@ -426,17 +427,33 @@ export class WorkspaceResolver {if (sendInviteMail) {const inviteInfo = await this.getInviteInfo(inviteId);- await this.mailer.sendInviteEmail(email, inviteId, {- workspace: {- id: inviteInfo.workspace.id,- name: inviteInfo.workspace.name,- avatar: inviteInfo.workspace.avatar,- },- user: {- avatar: inviteInfo.user?.avatarUrl || '',- name: inviteInfo.user?.name || '',- },- });+ try {+ await this.mailer.sendInviteEmail(email, inviteId, {+ workspace: {+ id: inviteInfo.workspace.id,+ name: inviteInfo.workspace.name,+ avatar: inviteInfo.workspace.avatar,+ },+ user: {+ 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;} else {@@ -449,17 +466,33 @@ export class WorkspaceResolver {if (sendInviteMail) {const inviteInfo = await this.getInviteInfo(inviteId);- await this.mailer.sendInviteEmail(email, inviteId, {- workspace: {- id: inviteInfo.workspace.id,- name: inviteInfo.workspace.name,- avatar: inviteInfo.workspace.avatar,- },- user: {- avatar: inviteInfo.user?.avatarUrl || '',- name: inviteInfo.user?.name || '',- },- });+ try {+ await this.mailer.sendInviteEmail(email, inviteId, {+ workspace: {+ id: inviteInfo.workspace.id,+ name: inviteInfo.workspace.name,+ avatar: inviteInfo.workspace.avatar,+ },+ user: {+ 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;}