Skip to content

Commit

Permalink
Prevent the creation of a second home page (#2865)
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Fichtner <[email protected]>
Co-authored-by: Johannes Obermair <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 799bf33 commit 6778c4e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/clever-radios-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@comet/cms-admin": patch
"@comet/cms-api": patch
---

Prevent the creation of a second home page
6 changes: 4 additions & 2 deletions packages/admin/cms-admin/src/pages/createEditPageNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ export function createEditPageNode({
});

let parentPath: string | null = null;
const hasParentNode = parentNodeData?.pageTreeNode?.path != undefined;

if (parentNodeData?.pageTreeNode) {
parentPath = parentNodeData.pageTreeNode.slug === "home" ? "/home" : parentNodeData.pageTreeNode.path;
parentPath = parentNodeData.pageTreeNode.slug === "home" && hasParentNode ? "/home" : parentNodeData.pageTreeNode.path;
}

const options = Object.keys(documentTypes).map((type) => ({
Expand All @@ -150,6 +151,7 @@ export function createEditPageNode({
// The unchanged slug is expected to be available
return "Available";
}

const { data } = await apollo.query<GQLIsPathAvailableQuery, GQLIsPathAvailableQueryVariables>({
query: isPathAvailableQuery,
variables: {
Expand Down Expand Up @@ -338,7 +340,7 @@ export function createEditPageNode({
variant="horizontal"
>
<Typography>
{values.slug === "home"
{values.slug === "home" && parentPath === null
? "/"
: parentPath === null
? `/${values.slug}`
Expand Down
5 changes: 5 additions & 0 deletions packages/api/cms-api/src/page-tree/createPageTreeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ export function createPageTreeResolver({
if (this.config.reservedPaths.includes(requestedPath)) {
return SlugAvailability.Reserved;
}

if (slug == "home" && requestedPath !== "/home") {
return SlugAvailability.Reserved;
}

const nodeWithSamePath = await this.pageTreeService.nodeWithSamePath(requestedPath, nonEmptyScopeOrNothing(scope));

if (nodeWithSamePath) {
Expand Down

0 comments on commit 6778c4e

Please sign in to comment.