diff --git a/apps/client/src/features/auth/components/setup-workspace-form.tsx b/apps/client/src/features/auth/components/setup-workspace-form.tsx index fe70782d..d15a7a28 100644 --- a/apps/client/src/features/auth/components/setup-workspace-form.tsx +++ b/apps/client/src/features/auth/components/setup-workspace-form.tsx @@ -21,7 +21,7 @@ import { Link } from "react-router-dom"; import APP_ROUTE from "@/lib/app-route.ts"; const formSchema = z.object({ - workspaceName: z.string().trim().min(3).max(50), + workspaceName: z.string().trim().max(50).optional(), name: z.string().min(1).max(50), email: z .string() @@ -46,6 +46,7 @@ export function SetupWorkspaceForm() { }); async function onSubmit(data: ISetupWorkspace) { + console.log(data) await setupWorkspace(data); } @@ -60,15 +61,17 @@ export function SetupWorkspaceForm() { {isCloud() && }
- + {!isCloud() && ( + + )} ; diff --git a/apps/client/src/features/workspace/components/settings/components/workspace-name-form.tsx b/apps/client/src/features/workspace/components/settings/components/workspace-name-form.tsx index d98d32ef..f8cd5d2d 100644 --- a/apps/client/src/features/workspace/components/settings/components/workspace-name-form.tsx +++ b/apps/client/src/features/workspace/components/settings/components/workspace-name-form.tsx @@ -11,7 +11,7 @@ import useUserRole from "@/hooks/use-user-role.tsx"; import { useTranslation } from "react-i18next"; const formSchema = z.object({ - name: z.string().min(4), + name: z.string().min(1), }); type FormValues = z.infer; diff --git a/apps/server/src/common/helpers/utils.ts b/apps/server/src/common/helpers/utils.ts index d1748850..87448bc7 100644 --- a/apps/server/src/common/helpers/utils.ts +++ b/apps/server/src/common/helpers/utils.ts @@ -16,6 +16,12 @@ export async function comparePasswordHash( return bcrypt.compare(plainPassword, passwordHash); } +export function generateRandomSuffixNumbers(length: number) { + return Math.random() + .toFixed(length) + .substring(2, 2 + length); +} + export type RedisConfig = { host: string; port: number; diff --git a/apps/server/src/core/auth/dto/create-admin-user.dto.ts b/apps/server/src/core/auth/dto/create-admin-user.dto.ts index fb6b4cb9..bdea75fe 100644 --- a/apps/server/src/core/auth/dto/create-admin-user.dto.ts +++ b/apps/server/src/core/auth/dto/create-admin-user.dto.ts @@ -1,6 +1,12 @@ -import { IsNotEmpty, IsString, MaxLength, MinLength } from 'class-validator'; +import { + IsNotEmpty, + IsOptional, + IsString, + MaxLength, + MinLength, +} from 'class-validator'; import { CreateUserDto } from './create-user.dto'; -import {Transform, TransformFnParams} from "class-transformer"; +import { Transform, TransformFnParams } from 'class-transformer'; export class CreateAdminUserDto extends CreateUserDto { @IsNotEmpty() @@ -9,10 +15,17 @@ export class CreateAdminUserDto extends CreateUserDto { @Transform(({ value }: TransformFnParams) => value?.trim()) name: string; - @IsNotEmpty() - @MinLength(3) + @IsOptional() + @MinLength(1) @MaxLength(50) @IsString() @Transform(({ value }: TransformFnParams) => value?.trim()) workspaceName: string; + + @IsOptional() + @MinLength(4) + @MaxLength(50) + @IsString() + @Transform(({ value }: TransformFnParams) => value?.trim()) + hostname?: string; } diff --git a/apps/server/src/core/auth/services/signup.service.ts b/apps/server/src/core/auth/services/signup.service.ts index a6921c89..bf089478 100644 --- a/apps/server/src/core/auth/services/signup.service.ts +++ b/apps/server/src/core/auth/services/signup.service.ts @@ -92,7 +92,8 @@ export class SignupService { // create workspace with full setup const workspaceData: CreateWorkspaceDto = { - name: createAdminUserDto.workspaceName, + name: createAdminUserDto.workspaceName || 'My workspace', + hostname: createAdminUserDto.hostname, }; workspace = await this.workspaceService.create( diff --git a/apps/server/src/core/workspace/services/workspace.service.ts b/apps/server/src/core/workspace/services/workspace.service.ts index d6359893..694eaa44 100644 --- a/apps/server/src/core/workspace/services/workspace.service.ts +++ b/apps/server/src/core/workspace/services/workspace.service.ts @@ -32,6 +32,7 @@ import { AttachmentType } from 'src/core/attachment/attachment.constants'; import { InjectQueue } from '@nestjs/bullmq'; import { QueueJob, QueueName } from '../../../integrations/queue/constants'; import { Queue } from 'bullmq'; +import { generateRandomSuffixNumbers } from '../../../common/helpers'; @Injectable() export class WorkspaceService { @@ -377,24 +378,20 @@ export class WorkspaceService { name: string, trx?: KyselyTransaction, ): Promise { - const generateRandomSuffix = (length: number) => - Math.random() - .toFixed(length) - .substring(2, 2 + length); - let subdomain = name .toLowerCase() - .replace(/[^a-z0-9]/g, '') - .substring(0, 20); + .replace(/[^a-z0-9-]/g, '') + .substring(0, 20) + .replace(/^-+|-+$/g, ''); //remove any hyphen at the start or end // Ensure we leave room for a random suffix. const maxSuffixLength = 6; if (subdomain.length < 4) { - subdomain = `${subdomain}-${generateRandomSuffix(maxSuffixLength)}`; + subdomain = `${subdomain}-${generateRandomSuffixNumbers(maxSuffixLength)}`; } if (DISALLOWED_HOSTNAMES.includes(subdomain)) { - subdomain = `workspace-${generateRandomSuffix(maxSuffixLength)}`; + subdomain = `workspace-${generateRandomSuffixNumbers(maxSuffixLength)}`; } let uniqueHostname = subdomain; @@ -408,7 +405,7 @@ export class WorkspaceService { break; } // Append a random suffix and retry. - const randomSuffix = generateRandomSuffix(maxSuffixLength); + const randomSuffix = generateRandomSuffixNumbers(maxSuffixLength); uniqueHostname = `${subdomain}-${randomSuffix}`.substring(0, 25); } diff --git a/apps/server/src/ee b/apps/server/src/ee index 4d1b0a17..397352b9 160000 --- a/apps/server/src/ee +++ b/apps/server/src/ee @@ -1 +1 @@ -Subproject commit 4d1b0a17d3be96d4f39bef6780d88b6c7fe49df9 +Subproject commit 397352b9f466d90d306f7d7d47d107be95655f05