fix: Incorrect role information in collection added email

This commit is contained in:
Tom Moor
2024-04-02 19:05:42 -04:00
parent 365f4c4b1f
commit 4311aac4ff
4 changed files with 15 additions and 2 deletions

View File

@@ -112,6 +112,7 @@ router.get(
if (user.isInvited) { if (user.isInvited) {
await new WelcomeEmail({ await new WelcomeEmail({
to: user.email, to: user.email,
role: user.role,
teamUrl: user.team.url, teamUrl: user.team.url,
}).schedule(); }).schedule();

View File

@@ -153,6 +153,7 @@ async function accountProvisioner({
if (isNewUser) { if (isNewUser) {
await new WelcomeEmail({ await new WelcomeEmail({
to: user.email, to: user.email,
role: user.role,
teamUrl: team.url, teamUrl: team.url,
}).schedule(); }).schedule();
} }

View File

@@ -75,7 +75,7 @@ View Document: ${teamUrl}${collection.path}
const permission = const permission =
membership.permission === CollectionPermission.ReadWrite membership.permission === CollectionPermission.ReadWrite
? "view and edit" ? "view and edit"
: CollectionPermission.Admin : membership.permission === CollectionPermission.Admin
? "manage" ? "manage"
: "view"; : "view";

View File

@@ -1,4 +1,5 @@
import * as React from "react"; import * as React from "react";
import { UserRole } from "@shared/types";
import env from "@server/env"; import env from "@server/env";
import BaseEmail, { EmailProps } from "./BaseEmail"; import BaseEmail, { EmailProps } from "./BaseEmail";
import Body from "./components/Body"; import Body from "./components/Body";
@@ -10,18 +11,28 @@ import Header from "./components/Header";
import Heading from "./components/Heading"; import Heading from "./components/Heading";
type Props = EmailProps & { type Props = EmailProps & {
role: UserRole;
teamUrl: string; teamUrl: string;
}; };
type BeforeSend = Record<string, never>;
/** /**
* Email sent to a user when their account has just been created, or they signed * Email sent to a user when their account has just been created, or they signed
* in for the first time from an invite. * in for the first time from an invite.
*/ */
export default class WelcomeEmail extends BaseEmail<Props> { export default class WelcomeEmail extends BaseEmail<Props, BeforeSend> {
protected subject() { protected subject() {
return `Welcome to ${env.APP_NAME}`; return `Welcome to ${env.APP_NAME}`;
} }
protected async beforeSend(props: Props) {
if (props.role === UserRole.Guest) {
return false;
}
return {};
}
protected preview() { protected preview() {
return `${env.APP_NAME} is a place for your team to build and share knowledge.`; return `${env.APP_NAME} is a place for your team to build and share knowledge.`;
} }