centralize email parsing logic

This commit is contained in:
Tom Moor
2024-07-07 10:54:19 -04:00
parent c484d1defe
commit bdcde1aa53
8 changed files with 52 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
import { InferCreationAttributes } from "sequelize";
import { UserRole } from "@shared/types";
import { parseEmail } from "@shared/utils/email";
import InviteAcceptedEmail from "@server/emails/templates/InviteAcceptedEmail";
import {
DomainNotAllowedError,
@@ -226,7 +227,7 @@ export default async function userProvisioner({
// If the team settings do not allow this domain,
// throw an error and fail user creation.
const domain = email.split("@")[1];
const { domain } = parseEmail(email);
if (team && !(await team.isDomainAllowed(domain))) {
throw DomainNotAllowedError();
}

View File

@@ -1,5 +1,6 @@
import "./bootstrap";
import { UserRole } from "@shared/types";
import { parseEmail } from "@shared/utils/email";
import teamCreator from "@server/commands/teamCreator";
import env from "@server/env";
import { Team, User } from "@server/models";
@@ -10,6 +11,7 @@ const email = process.argv[2];
export default async function main(exit = false) {
const teamCount = await Team.count();
if (teamCount === 0) {
const name = parseEmail(email).local;
const user = await sequelize.transaction(async (transaction) => {
const team = await teamCreator({
name: "Wiki",
@@ -22,7 +24,7 @@ export default async function main(exit = false) {
return await User.create(
{
teamId: team.id,
name: email.split("@")[0],
name,
email,
role: UserRole.Admin,
},