/** * Copyright since 2025 Mifos Initiative * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { inject } from '@angular/core'; import { Router, CanActivateFn } from '@angular/router'; /** * Accounting features switched off for this installation. * * Nothing is deleted — the components, routes and services all stay in place, and flipping a flag * back to `false` brings the feature back with its tile and its route. The matching API block lives * in DisabledFeatureApiFilter on the backend, so a hidden feature cannot be reached by calling the * endpoint directly either. */ export const DISABLED_ACCOUNTING_FEATURES = { createJournalEntries: true, frequentPostings: true, closingEntries: true, accruals: true, provisioningEntries: true, accountingRules: true }; /** * Blocks a route belonging to a disabled feature, for anyone who reaches it by typing the URL * rather than through a tile. `data.feature` names the flag to check. */ export const accountingFeatureEnabledGuard: CanActivateFn = (route) => { const router = inject(Router); const feature = route.data?.['feature'] as keyof typeof DISABLED_ACCOUNTING_FEATURES | undefined; if (!feature || !DISABLED_ACCOUNTING_FEATURES[feature]) { return true; } router.navigate(['/accounting'], { replaceUrl: true }); return false; };