fix: disable emails for platform (#15089)
* disable emails for platform * check for if user is platform and skip verification accordingly * skip isPlatform check for verify email in create org handler * use if instead of && --------- Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
This commit is contained in:
@@ -20,6 +20,7 @@ interface VerifyEmailType {
|
||||
email: string;
|
||||
language?: string;
|
||||
secondaryEmailId?: number;
|
||||
isPlatform?: boolean;
|
||||
}
|
||||
|
||||
export const sendEmailVerification = async ({
|
||||
@@ -27,6 +28,7 @@ export const sendEmailVerification = async ({
|
||||
language,
|
||||
username,
|
||||
secondaryEmailId,
|
||||
isPlatform = false,
|
||||
}: VerifyEmailType) => {
|
||||
const token = randomBytes(32).toString("hex");
|
||||
const translation = await getTranslation(language ?? "en", "common");
|
||||
@@ -37,6 +39,11 @@ export const sendEmailVerification = async ({
|
||||
return { ok: true, skipped: true };
|
||||
}
|
||||
|
||||
if (isPlatform) {
|
||||
log.warn("Skipping Email verification");
|
||||
return { ok: true, skipped: true };
|
||||
}
|
||||
|
||||
await checkRateLimitAndThrowError({
|
||||
rateLimitingType: "core",
|
||||
identifier: email,
|
||||
|
||||
@@ -161,19 +161,22 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
|
||||
email: orgOwnerEmail,
|
||||
language: ctx.user.locale,
|
||||
username: ownerProfile.username || "",
|
||||
isPlatform: isPlatform,
|
||||
});
|
||||
|
||||
await sendOrganizationCreationEmail({
|
||||
language: translation,
|
||||
from: ctx.user.name ?? `${organization.name}'s admin`,
|
||||
to: orgOwnerEmail,
|
||||
ownerNewUsername: ownerProfile.username,
|
||||
ownerOldUsername: null,
|
||||
orgDomain: getOrgFullOrigin(slug, { protocol: false }),
|
||||
orgName: organization.name,
|
||||
prevLink: null,
|
||||
newLink: `${getOrgFullOrigin(slug, { protocol: true })}/${ownerProfile.username}`,
|
||||
});
|
||||
if (!isPlatform) {
|
||||
await sendOrganizationCreationEmail({
|
||||
language: translation,
|
||||
from: ctx.user.name ?? `${organization.name}'s admin`,
|
||||
to: orgOwnerEmail,
|
||||
ownerNewUsername: ownerProfile.username,
|
||||
ownerOldUsername: null,
|
||||
orgDomain: getOrgFullOrigin(slug, { protocol: false }),
|
||||
orgName: organization.name,
|
||||
prevLink: null,
|
||||
newLink: `${getOrgFullOrigin(slug, { protocol: true })}/${ownerProfile.username}`,
|
||||
});
|
||||
}
|
||||
|
||||
const user = await UserRepository.enrichUserWithItsProfile({
|
||||
user: { ...orgOwner, organizationId: organization.id },
|
||||
@@ -202,17 +205,19 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
|
||||
},
|
||||
});
|
||||
|
||||
await sendOrganizationCreationEmail({
|
||||
language: inputLanguageTranslation,
|
||||
from: ctx.user.name ?? `${organization.name}'s admin`,
|
||||
to: orgOwnerEmail,
|
||||
ownerNewUsername: ownerProfile.username,
|
||||
ownerOldUsername: nonOrgUsernameForOwner,
|
||||
orgDomain: getOrgFullOrigin(slug, { protocol: false }),
|
||||
orgName: organization.name,
|
||||
prevLink: `${getOrgFullOrigin("", { protocol: true })}/${nonOrgUsernameForOwner}`,
|
||||
newLink: `${getOrgFullOrigin(slug, { protocol: true })}/${ownerProfile.username}`,
|
||||
});
|
||||
if (!isPlatform) {
|
||||
await sendOrganizationCreationEmail({
|
||||
language: inputLanguageTranslation,
|
||||
from: ctx.user.name ?? `${organization.name}'s admin`,
|
||||
to: orgOwnerEmail,
|
||||
ownerNewUsername: ownerProfile.username,
|
||||
ownerOldUsername: nonOrgUsernameForOwner,
|
||||
orgDomain: getOrgFullOrigin(slug, { protocol: false }),
|
||||
orgName: organization.name,
|
||||
prevLink: `${getOrgFullOrigin("", { protocol: true })}/${nonOrgUsernameForOwner}`,
|
||||
newLink: `${getOrgFullOrigin(slug, { protocol: true })}/${ownerProfile.username}`,
|
||||
});
|
||||
}
|
||||
|
||||
if (!organization.id) throw Error("User not created");
|
||||
const user = await UserRepository.enrichUserWithItsProfile({
|
||||
|
||||
Reference in New Issue
Block a user