diff --git a/packages/server-core/src/aggregators/authup/entities/index.ts b/packages/server-core/src/aggregators/authup/entities/index.ts index 4de768bc7..8980db113 100644 --- a/packages/server-core/src/aggregators/authup/entities/index.ts +++ b/packages/server-core/src/aggregators/authup/entities/index.ts @@ -6,6 +6,7 @@ */ export * from './permission'; +export * from './policy'; export * from './realm'; export * from './robot'; export * from './user'; diff --git a/packages/server-core/src/aggregators/authup/entities/policy.ts b/packages/server-core/src/aggregators/authup/entities/policy.ts new file mode 100644 index 000000000..3e585d710 --- /dev/null +++ b/packages/server-core/src/aggregators/authup/entities/policy.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023-2024. + * Author Peter Placzek (tada5hi) + * For the full copyright and license information, + * view the LICENSE file that was distributed with this source code. + */ +import type { PolicyEventContext } from '@authup/core-kit'; +import { useDataSource } from 'typeorm-extension'; +import { AnalysisPermissionEntity } from '../../../domains'; + +export async function handleAuthupPolicyEvent(context: PolicyEventContext) { + if (context.event !== 'deleted') { + return; + } + + const dataSource = await useDataSource(); + const repository = dataSource.getRepository(AnalysisPermissionEntity); + await repository.update({ + policy_id: context.data.id, + }, { + policy_id: null, + }); +} diff --git a/packages/server-core/src/aggregators/authup/module.ts b/packages/server-core/src/aggregators/authup/module.ts index 9453ec2c5..bd65d488e 100644 --- a/packages/server-core/src/aggregators/authup/module.ts +++ b/packages/server-core/src/aggregators/authup/module.ts @@ -10,7 +10,7 @@ import { isRedisClientUsable, useLogger, useRedisSubscribeClient } from '@privat import type { Aggregator } from '@privateaim/server-kit'; import { EnvironmentName, useEnv } from '../../config'; import { - handleAuthupPermissionEvent, + handleAuthupPermissionEvent, handleAuthupPolicyEvent, handleAuthupRealmEvent, handleAuthupRobotEvent, handleAuthupUserEvent, } from './entities'; @@ -30,6 +30,7 @@ export function createAuthupAggregator() : Aggregator { redisSub.subscribe( 'permission', + 'policy', 'realm', 'user', 'robot', @@ -40,6 +41,10 @@ export function createAuthupAggregator() : Aggregator { const event = JSON.parse(message); switch (event.type) { + case DomainType.POLICY: { + await handleAuthupPolicyEvent(event); + break; + } case DomainType.PERMISSION: { await handleAuthupPermissionEvent(event); break;