From 374d2e6d92f5a65c693a6e17da08f9c75acadc03 Mon Sep 17 00:00:00 2001 From: Pedro Sanders Date: Sat, 25 Nov 2023 17:44:20 -0500 Subject: [PATCH] fix(email): remove one-time password from invite for existing users --- mods/apiserver/src/notifications/createInviteBody.ts | 10 ++++++++-- .../templates/inviteExistingUserTemplate.hbs | 11 +++++++++++ .../{inviteTemplate.hbs => inviteNewUserTemplate.hbs} | 0 mods/apiserver/src/workspaces/addWorkspaceMember.ts | 3 ++- mods/frontoffice/src/containers/SettingsContainer.tsx | 4 ++-- 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 mods/apiserver/src/notifications/templates/inviteExistingUserTemplate.hbs rename mods/apiserver/src/notifications/templates/{inviteTemplate.hbs => inviteNewUserTemplate.hbs} (100%) diff --git a/mods/apiserver/src/notifications/createInviteBody.ts b/mods/apiserver/src/notifications/createInviteBody.ts index 82239b1..0dbb8a4 100644 --- a/mods/apiserver/src/notifications/createInviteBody.ts +++ b/mods/apiserver/src/notifications/createInviteBody.ts @@ -21,8 +21,10 @@ import fs from "fs"; import path from "path"; const TEMPLATE_DIR = path.join(__dirname, "templates"); + enum TemplateName { - INVITE = "inviteTemplate" + INVITE_NEW_USER = "inviteNewUserTemplate", + INVITE_EXISTING_USER = "inviteExistingUserTemplate" } const compileTemplate = ( @@ -36,5 +38,9 @@ const compileTemplate = ( }; export function createInviteBody(data: Record) { - return compileTemplate(TemplateName.INVITE, data); + if (data.oneTimePassword) { + return compileTemplate(TemplateName.INVITE_NEW_USER, data); + } else { + return compileTemplate(TemplateName.INVITE_EXISTING_USER, data); + } } diff --git a/mods/apiserver/src/notifications/templates/inviteExistingUserTemplate.hbs b/mods/apiserver/src/notifications/templates/inviteExistingUserTemplate.hbs new file mode 100644 index 0000000..0c9f62d --- /dev/null +++ b/mods/apiserver/src/notifications/templates/inviteExistingUserTemplate.hbs @@ -0,0 +1,11 @@ + + + Invite + + +

Welcome to Goodtok

+

To accept the invitation, please click the following link: + {{inviteUrl}} +

+ + \ No newline at end of file diff --git a/mods/apiserver/src/notifications/templates/inviteTemplate.hbs b/mods/apiserver/src/notifications/templates/inviteNewUserTemplate.hbs similarity index 100% rename from mods/apiserver/src/notifications/templates/inviteTemplate.hbs rename to mods/apiserver/src/notifications/templates/inviteNewUserTemplate.hbs diff --git a/mods/apiserver/src/workspaces/addWorkspaceMember.ts b/mods/apiserver/src/workspaces/addWorkspaceMember.ts index 202346b..950a261 100644 --- a/mods/apiserver/src/workspaces/addWorkspaceMember.ts +++ b/mods/apiserver/src/workspaces/addWorkspaceMember.ts @@ -65,9 +65,10 @@ export async function addWorkspaceMember( } }); - const oneTimePassword = customAlphabet("1234567890abcdef", 10)(); + let oneTimePassword; if (!user) { + oneTimePassword = customAlphabet("1234567890abcdef", 10)(); // Let's create a new user with a one time password logger.verbose("user does not exists, creating a new one", { email diff --git a/mods/frontoffice/src/containers/SettingsContainer.tsx b/mods/frontoffice/src/containers/SettingsContainer.tsx index d77b0aa..564e0f4 100644 --- a/mods/frontoffice/src/containers/SettingsContainer.tsx +++ b/mods/frontoffice/src/containers/SettingsContainer.tsx @@ -234,7 +234,7 @@ function SettingsContainer() { workspaces .getMembersByWorkspaceId(workspaceId) .then((response) => { - const newMembers = response.members.map((member) => ({ + const members = response.members.map((member) => ({ id: member.id, userId: member.userId, name: member.name, @@ -244,7 +244,7 @@ function SettingsContainer() { createdAt: new Date(member.createdAt) })); - setMembers((prevMembers) => [prevMembers[0], ...newMembers]); + setMembers(members); }) .catch((err) => { logger.error("error getting workspace members", err);