mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
feat(server): role changed email (#9227)
This commit is contained in:
@@ -166,7 +166,7 @@ function generateErrorArgs(name: string, args: ErrorArgs) {
|
||||
|
||||
export function generateUserFriendlyErrors() {
|
||||
const output = [
|
||||
'/* eslint-disable */',
|
||||
'/* oxlint-disable */',
|
||||
'// AUTO GENERATED FILE',
|
||||
`import { createUnionType, Field, ObjectType, registerEnumType } from '@nestjs/graphql';`,
|
||||
'',
|
||||
@@ -374,10 +374,6 @@ export const USER_FRIENDLY_ERRORS = {
|
||||
args: { spaceId: 'string' },
|
||||
message: ({ spaceId }) => `Owner of Space ${spaceId} not found.`,
|
||||
},
|
||||
cant_change_space_owner: {
|
||||
type: 'action_forbidden',
|
||||
message: 'You are not allowed to change the owner of a Space.',
|
||||
},
|
||||
doc_not_found: {
|
||||
type: 'resource_not_found',
|
||||
args: { spaceId: 'string', docId: 'string' },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable */
|
||||
/* oxlint-disable */
|
||||
// AUTO GENERATED FILE
|
||||
import { createUnionType, Field, ObjectType, registerEnumType } from '@nestjs/graphql';
|
||||
|
||||
@@ -240,12 +240,6 @@ export class SpaceOwnerNotFound extends UserFriendlyError {
|
||||
super('internal_server_error', 'space_owner_not_found', message, args);
|
||||
}
|
||||
}
|
||||
|
||||
export class CantChangeSpaceOwner extends UserFriendlyError {
|
||||
constructor(message?: string) {
|
||||
super('action_forbidden', 'cant_change_space_owner', message);
|
||||
}
|
||||
}
|
||||
@ObjectType()
|
||||
class DocNotFoundDataType {
|
||||
@Field() spaceId!: string
|
||||
@@ -630,7 +624,6 @@ export enum ErrorNames {
|
||||
ALREADY_IN_SPACE,
|
||||
SPACE_ACCESS_DENIED,
|
||||
SPACE_OWNER_NOT_FOUND,
|
||||
CANT_CHANGE_SPACE_OWNER,
|
||||
DOC_NOT_FOUND,
|
||||
DOC_ACCESS_DENIED,
|
||||
VERSION_REJECTED,
|
||||
|
||||
@@ -10,6 +10,12 @@ export interface WorkspaceEvents {
|
||||
workspaceId: Workspace['id'];
|
||||
}>;
|
||||
requestApproved: Payload<{ inviteId: string }>;
|
||||
roleChanged: Payload<{
|
||||
userId: User['id'];
|
||||
workspaceId: Workspace['id'];
|
||||
permission: number;
|
||||
}>;
|
||||
ownerTransferred: Payload<{ email: string; workspaceId: Workspace['id'] }>;
|
||||
updated: Payload<{ workspaceId: Workspace['id']; count: number }>;
|
||||
};
|
||||
deleted: Payload<Workspace['id']>;
|
||||
|
||||
@@ -6,7 +6,12 @@ import { URLHelper } from '../helpers';
|
||||
import { metrics } from '../metrics';
|
||||
import type { MailerService, Options } from './mailer';
|
||||
import { MAILER_SERVICE } from './mailer';
|
||||
import { emailTemplate } from './template';
|
||||
import {
|
||||
emailTemplate,
|
||||
getRoleChangedTemplate,
|
||||
type RoleChangedMailParams,
|
||||
} from './template';
|
||||
|
||||
@Injectable()
|
||||
export class MailService {
|
||||
constructor(
|
||||
@@ -311,4 +316,22 @@ export class MailService {
|
||||
});
|
||||
return this.sendMail({ to, subject: title, html });
|
||||
}
|
||||
|
||||
async sendRoleChangedEmail(to: string, ws: RoleChangedMailParams) {
|
||||
const { subject, title, content } = getRoleChangedTemplate(ws);
|
||||
const html = emailTemplate({ title, content });
|
||||
console.log({ subject, title, content, to });
|
||||
return this.sendMail({ to, subject, html });
|
||||
}
|
||||
|
||||
async sendOwnerTransferred(to: string, ws: { name: string }) {
|
||||
const { name: workspaceName } = ws;
|
||||
const title = `Your ownership of ${workspaceName} has been transferred`;
|
||||
|
||||
const html = emailTemplate({
|
||||
title: 'Ownership transferred',
|
||||
content: `You have transferred ownership of ${workspaceName}. You are now a admin in this workspace.`,
|
||||
});
|
||||
return this.sendMail({ to, subject: title, html });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,3 +219,38 @@ export const emailTemplate = ({
|
||||
</table>
|
||||
</body>`;
|
||||
};
|
||||
|
||||
type RoleChangedMail = {
|
||||
subject: string;
|
||||
title: string;
|
||||
content: string;
|
||||
};
|
||||
|
||||
export type RoleChangedMailParams = {
|
||||
name: string;
|
||||
role: 'owner' | 'admin' | 'member' | 'readonly';
|
||||
};
|
||||
|
||||
export const getRoleChangedTemplate = (
|
||||
ws: RoleChangedMailParams
|
||||
): RoleChangedMail => {
|
||||
const { name, role } = ws;
|
||||
let subject = `You are now an ${role} of ${name}`;
|
||||
let title = 'Role update in workspace';
|
||||
let content = `Your role in ${name} has been changed to ${role}. You can continue to collaborate in this workspace.`;
|
||||
|
||||
switch (role) {
|
||||
case 'owner':
|
||||
title = 'Welcome, new workspace owner!';
|
||||
content = `You have been assigned as the owner of ${name}. As a workspace owner, you have full control over this team workspace.`;
|
||||
break;
|
||||
case 'admin':
|
||||
title = `You've been promoted to admin.`;
|
||||
content = `You have been promoted to admin of ${name}. As an admin, you can help the workspace owner manage members in this workspace.`;
|
||||
break;
|
||||
default:
|
||||
subject = `Your role has been changed in ${name}`;
|
||||
break;
|
||||
}
|
||||
return { subject, title, content };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user