diff --git a/plugins/controlled-documents-resources/src/components/hierarchy/DocumentSpacePresenter.svelte b/plugins/controlled-documents-resources/src/components/hierarchy/DocumentSpacePresenter.svelte index b35655b010..5ecdcd1746 100644 --- a/plugins/controlled-documents-resources/src/components/hierarchy/DocumentSpacePresenter.svelte +++ b/plugins/controlled-documents-resources/src/components/hierarchy/DocumentSpacePresenter.svelte @@ -39,7 +39,8 @@ setCurrentProject, getProjectDocsHierarchy, isEditableProject, - createDocument + createDocument, + canCreateChildDocument } from '../../utils' import documents from '../../plugin' @@ -129,17 +130,19 @@ async function getSpaceActions (space: DocumentSpace): Promise { const actions = await getActions(space) - const action: Action = { - icon: documents.icon.NewDocument, - label: documents.string.CreateDocument, - group: 'create', - action: async () => { - await createDocument(space) - } - } - - if (spaceType?.projects === true && (await isEditableProject(project))) { - actions.push(action) + if ( + spaceType?.projects === true && + (await isEditableProject(project)) && + (await canCreateChildDocument(space, true)) + ) { + actions.push({ + icon: documents.icon.NewDocument, + label: documents.string.CreateDocument, + group: 'create', + action: async () => { + await createDocument(space) + } + }) } return orderActions(actions) diff --git a/plugins/controlled-documents-resources/src/utils.ts b/plugins/controlled-documents-resources/src/utils.ts index e8dea554e3..fade208bbe 100644 --- a/plugins/controlled-documents-resources/src/utils.ts +++ b/plugins/controlled-documents-resources/src/utils.ts @@ -605,7 +605,8 @@ export async function canCreateChildTemplate ( } export async function canCreateChildDocument ( - doc?: Document | Document[] | DocumentSpace | DocumentSpace[] | ProjectDocument | ProjectDocument[] + doc?: Document | Document[] | DocumentSpace | DocumentSpace[] | ProjectDocument | ProjectDocument[], + includeProjects = false ): Promise { if (doc === null || doc === undefined) { return false @@ -625,7 +626,7 @@ export async function canCreateChildDocument ( if (isSpace(hierarchy, doc)) { const spaceType = await client.findOne(documents.class.DocumentSpaceType, { _id: doc.type }) - return spaceType?.projects !== true + return includeProjects || spaceType?.projects !== true } if (isProjectDocument(hierarchy, doc)) {