Fix logic to update parent bundles enabled status (#22587)

This commit is contained in:
ian
2024-05-28 21:26:38 +08:00
committed by GitHub
parent 67d5161c5f
commit f073a5335e
2 changed files with 16 additions and 7 deletions

View File

@@ -0,0 +1,5 @@
---
'@directus/api': patch
---
Fixed logic to update parent bundles enabled status

View File

@@ -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 });
}
}
}