Convert isViewer and isAdmin to getters (#6724)

This commit is contained in:
Tom Moor
2024-03-28 17:00:35 -06:00
committed by GitHub
parent 278b81a8fb
commit 0dede0b56e
20 changed files with 113 additions and 139 deletions

View File

@@ -1,4 +1,5 @@
import { InferCreationAttributes } from "sequelize";
import { UserRole } from "@shared/types";
import InviteAcceptedEmail from "@server/emails/templates/InviteAcceptedEmail";
import {
DomainNotAllowedError,
@@ -22,8 +23,8 @@ type Props = {
email: string;
/** The language of the user, if known */
language?: string;
/** Provision the new user as an administrator */
isAdmin?: boolean;
/** The role for new user, Member if none is provided */
role?: UserRole;
/** The public url of an image representing the user */
avatarUrl?: string | null;
/**
@@ -52,7 +53,7 @@ type Props = {
export default async function userProvisioner({
name,
email,
isAdmin,
role,
language,
avatarUrl,
teamId,
@@ -230,15 +231,12 @@ export default async function userProvisioner({
throw DomainNotAllowedError();
}
const defaultUserRole = team?.defaultUserRole;
const user = await User.create(
{
name,
email,
language,
isAdmin: typeof isAdmin === "boolean" && isAdmin,
isViewer: isAdmin === true ? false : defaultUserRole === "viewer",
role: role ?? team?.defaultUserRole,
teamId,
avatarUrl,
authentications: authentication ? [authentication] : [],