mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-20 11:31:47 +08:00
feat(server): role changed email (#9227)
This commit is contained in:
@@ -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