Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/modules/kwp/routes/kwpAccess.server.ts
T

29 lines
1.2 KiB
TypeScript

import { featureKeys } from "@hivegrid/entitlements";
import { CatalogError, foundationErrors } from "@hivegrid/foundation";
import { loadRequiredWebConfig } from "@hivegrid/config";
import { tenantHasModule } from "~/utils/connector/tenantConnector.server";
import type { IntegrationsRouteContext } from "~/utils/integrations/integrationsAccess.server";
export const KWP_INTEGRATION_MODULE_KEY = featureKeys.kwpIntegration;
export async function hasKwpIntegrationModule(context: IntegrationsRouteContext): Promise<boolean> {
const configuredTenantId = loadRequiredWebConfig().kwp?.hiveGridTenantId?.trim();
if (!configuredTenantId || configuredTenantId !== context.tenantId) return false;
return tenantHasModule({
tenantId: context.tenantId,
userId: context.userId,
moduleKey: KWP_INTEGRATION_MODULE_KEY,
});
}
/** Fail closed with the platform's 404 permission semantics. */
export async function requireKwpIntegrationModule(
context: IntegrationsRouteContext,
): Promise<IntegrationsRouteContext> {
if (!(await hasKwpIntegrationModule(context))) {
throw new CatalogError(foundationErrors.notFound, { module: KWP_INTEGRATION_MODULE_KEY });
}
return context;
}