diff --git a/.changeset/two-walls-deliver.md b/.changeset/two-walls-deliver.md new file mode 100644 index 0000000000..64e0588c02 --- /dev/null +++ b/.changeset/two-walls-deliver.md @@ -0,0 +1,5 @@ +--- +'@directus/api': patch +--- + +Fixed logic to update parent bundles enabled status diff --git a/api/src/services/extensions.ts b/api/src/services/extensions.ts index 257b6ffdf2..f57d31c5e4 100644 --- a/api/src/services/extensions.ts +++ b/api/src/services/extensions.ts @@ -245,18 +245,22 @@ export class ExtensionsService { * - Entry status change resulted in all children being disabled then the parent bundle is disabled * - Entry status change resulted in at least one child being enabled then the parent bundle is enabled */ - private async checkBundleAndSyncStatus(trx: Knex, bundleId: string, extension: ApiOutput) { + private async checkBundleAndSyncStatus(trx: Knex, extensionId: string, extension: ApiOutput) { if (extension.bundle === null && extension.schema?.type === 'bundle') { // If extension is the parent bundle, set it and all nested extensions to enabled await trx('directus_extensions') .update({ enabled: extension.meta.enabled }) - .where({ bundle: bundleId }) - .orWhere({ id: bundleId }); + .where({ bundle: extensionId }) + .orWhere({ id: extensionId }); return; } - const parent = await this.readOne(bundleId); + const parentId = extension.bundle ?? extension.meta.bundle; + + if (!parentId) return; + + const parent = await this.readOne(parentId); if (parent.schema?.type !== 'bundle') { return; @@ -269,14 +273,14 @@ export class ExtensionsService { } const hasEnabledChildren = !!(await trx('directus_extensions') - .where({ bundle: bundleId }) + .where({ bundle: parentId }) .where({ enabled: true }) .first()); if (hasEnabledChildren) { - await trx('directus_extensions').update({ enabled: true }).where({ id: bundleId }); + await trx('directus_extensions').update({ enabled: true }).where({ id: parentId }); } else { - await trx('directus_extensions').update({ enabled: false }).where({ id: bundleId }); + await trx('directus_extensions').update({ enabled: false }).where({ id: parentId }); } } }