Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(views): validate workspace slug against reserved ones when creating (#2228)

Mark Gazec926dfe44bb6
diff --git a/packages/views/onboarding/steps/step-workspace.tsx b/packages/views/onboarding/steps/step-workspace.tsx
index de7a2a3772..e74ea70363 100644
--- a/packages/views/onboarding/steps/step-workspace.tsx
+++ b/packages/views/onboarding/steps/step-workspace.tsx
@@ -33,9 +33,11 @@ import {
WORKSPACE_SLUG_CONFLICT_ERROR,
WORKSPACE_SLUG_FORMAT_ERROR,
WORKSPACE_SLUG_REGEX,
+ WORKSPACE_SLUG_RESERVED_ERROR,
isWorkspaceSlugConflict,
nameToWorkspaceSlug,
} from "../../workspace/slug";
+import { isReservedSlug } from "@multica/core/paths";
/**
* Step 2 — create your first workspace, or continue with one set up in
@@ -104,7 +106,8 @@ export function StepWorkspace({
slug.length > 0 && !WORKSPACE_SLUG_REGEX.test(slug)
? WORKSPACE_SLUG_FORMAT_ERROR
: null;
- const slugError = slugValidationError ?? slugServerError;
+ const slugReservedError = slug.length > 0 && isReservedSlug(slug) ? WORKSPACE_SLUG_RESERVED_ERROR : null;
+ const slugError = slugValidationError ?? slugReservedError ?? slugServerError;
const canCreate =
name.trim().length > 0 && slug.trim().length > 0 && !slugError;
diff --git a/packages/views/workspace/create-workspace-form.test.tsx b/packages/views/workspace/create-workspace-form.test.tsx
index 6c2baf1c03..b0433b68fa 100644
--- a/packages/views/workspace/create-workspace-form.test.tsx
+++ b/packages/views/workspace/create-workspace-form.test.tsx
@@ -99,4 +99,18 @@ describe("CreateWorkspaceForm", () => {
screen.getByRole("button", { name: /create workspace/i }),
).toBeDisabled();
});
+
+ it("disables submit when slug is reserved", () => {
+ renderForm();
+ fireEvent.change(screen.getByLabelText(/workspace name/i), {
+ target: { value: "Valid Name" },
+ });
+ fireEvent.change(screen.getByLabelText(/workspace url/i), {
+ target: { value: "admin" },
+ });
+ expect(
+ screen.getByRole("button", { name: /create workspace/i }),
+ ).toBeDisabled();
+ expect(screen.getByText(/reserved and cannot be used/i)).toBeInTheDocument();
+ });
});
diff --git a/packages/views/workspace/create-workspace-form.tsx b/packages/views/workspace/create-workspace-form.tsx
index 4737c4d381..6e7be41d6f 100644
--- a/packages/views/workspace/create-workspace-form.tsx
+++ b/packages/views/workspace/create-workspace-form.tsx
@@ -11,10 +11,12 @@ import type { Workspace } from "@multica/core/types";
import { isImeComposing } from "@multica/core/utils";
import {
WORKSPACE_SLUG_REGEX,
+ WORKSPACE_SLUG_RESERVED_ERROR,
isWorkspaceSlugConflict,
nameToWorkspaceSlug,
} from "./slug";
import { useT } from "../i18n";
+import { isReservedSlug } from "@multica/core/paths";
export interface CreateWorkspaceFormProps {
onSuccess: (workspace: Workspace) => void | Promise<void>;
@@ -32,7 +34,8 @@ export function CreateWorkspaceForm({ onSuccess }: CreateWorkspaceFormProps) {
slug.length > 0 && !WORKSPACE_SLUG_REGEX.test(slug)
? t(($) => $.create_form.errors.slug_format)
: null;
- const slugError = slugValidationError ?? slugServerError;
+ const slugReservedError = slug.length > 0 && isReservedSlug(slug) ? WORKSPACE_SLUG_RESERVED_ERROR : null;
+ const slugError = slugValidationError ?? slugReservedError ?? slugServerError;
const canSubmit =
name.trim().length > 0 && slug.trim().length > 0 && !slugError;
diff --git a/packages/views/workspace/slug.ts b/packages/views/workspace/slug.ts
index 6f027ba3fe..b22e9624e5 100644
--- a/packages/views/workspace/slug.ts
+++ b/packages/views/workspace/slug.ts
@@ -6,6 +6,9 @@ export const WORKSPACE_SLUG_FORMAT_ERROR =
export const WORKSPACE_SLUG_CONFLICT_ERROR =
"That workspace URL is already taken.";
+export const WORKSPACE_SLUG_RESERVED_ERROR =
+"That workspace URL is reserved and cannot be used.";
+
/**
* Auto-generate a slug from a workspace name.
*