Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/routes/app.$tenant/settings/compliance.tsx
T

97 lines
4.4 KiB
TypeScript

// AK-SET-01 Hub F — "Compliance & Protokolle" bundles the audit log, the audit
// export, the chat audit and the tenant-wide privacy administration. Layout
// route only.
//
// This hub is what finally makes the audit export reachable from navigation;
// before, it existed only as a deep link.
import { Outlet, useLoaderData, useLocation, type LoaderFunctionArgs, type MetaFunction } from "react-router";
import { FeatherClipboardList } from "@subframe/core";
import { buildSettingsHubVM, type SettingsHubTabInput } from "@hivegrid/view-models";
import { SettingsHubShell } from "~/components/screens/settings/SettingsHubShell";
import { getTranslations } from "~/locale/i18next.server";
import UrlUtils from "~/utils/app/UrlUtils";
import { getTenantIdFromUrl } from "~/utils/services/.server/urlService";
import { getUserInfo } from "~/utils/session.server";
import { tenantHasModule } from "~/utils/connector/tenantConnector.server";
import { CHAT_MODULE_KEY } from "~/modules/chat/routes/chatRoutePaths";
import { hasSettingsPermission, settingsHubBaseRedirect, settingsHubNotFound } from "./hub-access.server";
type LoaderData = {
title: string;
tabs: SettingsHubTabInput[];
};
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
const tenantId = await getTenantIdFromUrl(params);
const [{ t }, userInfo, canViewAudit, canReadChat, canExportTenant, canReadAvv, canReadSubprocessors, canDeleteTenant] = await Promise.all([
getTranslations(request),
getUserInfo(request),
hasSettingsPermission(request, "app.settings.auditTrails.view", tenantId),
hasSettingsPermission(request, "chat.read_all_channels", tenantId),
hasSettingsPermission(request, "privacy.tenant_export", tenantId),
hasSettingsPermission(request, "privacy.avv.read", tenantId),
hasSettingsPermission(request, "privacy.subprocessors.read", tenantId),
hasSettingsPermission(request, "privacy.tenant_deletion", tenantId),
]);
const chatEnabled = canReadChat && (await tenantHasModule({ tenantId, userId: userInfo.userId, moduleKey: CHAT_MODULE_KEY }));
const tabs: SettingsHubTabInput[] = [];
if (canViewAudit) {
// The hub index href is a prefix of every sibling — without this the log
// tab would stay lit everywhere.
tabs.push({ id: "log", labelKey: "settings.hubs.compliance.tabs.log", href: UrlUtils.currentTenantUrl(params, "settings/compliance"), exact: true });
tabs.push({ id: "auditExport", labelKey: "settings.hubs.compliance.tabs.auditExport", href: UrlUtils.currentTenantUrl(params, "settings/compliance/audit-export") });
}
if (chatEnabled) {
tabs.push({ id: "chat", labelKey: "settings.hubs.compliance.tabs.chat", href: UrlUtils.currentTenantUrl(params, "settings/compliance/chat") });
}
if (canExportTenant) {
tabs.push({ id: "dataExport", labelKey: "settings.hubs.compliance.tabs.dataExport", href: UrlUtils.currentTenantUrl(params, "settings/compliance/data-export") });
}
if (canReadAvv) {
tabs.push({ id: "avv", labelKey: "settings.hubs.compliance.tabs.avv", href: UrlUtils.currentTenantUrl(params, "settings/compliance/avv") });
}
if (canReadSubprocessors) {
tabs.push({
id: "subprocessors",
labelKey: "settings.hubs.compliance.tabs.subprocessors",
href: UrlUtils.currentTenantUrl(params, "settings/compliance/subprocessors"),
});
}
if (canDeleteTenant) {
tabs.push({
id: "tenantDeletion",
labelKey: "settings.hubs.compliance.tabs.tenantDeletion",
href: UrlUtils.currentTenantUrl(params, "settings/compliance/tenant-deletion"),
});
}
if (tabs.length === 0) throw settingsHubNotFound();
const baseRedirect = settingsHubBaseRedirect(request, UrlUtils.currentTenantUrl(params, "settings/compliance"), tabs);
if (baseRedirect) throw baseRedirect;
return { title: `${t("settings.hubs.compliance.title")} | ${process.env.APP_NAME}`, tabs } satisfies LoaderData;
};
export const meta: MetaFunction<typeof loader> = ({ data }) => [{ title: data?.title }];
export default function ComplianceHubRoute() {
const { tabs } = useLoaderData<LoaderData>();
const location = useLocation();
const vm = buildSettingsHubVM({
hubId: "compliance",
titleKey: "settings.hubs.compliance.title",
subtitleKey: "settings.hubs.compliance.subtitle",
tabs,
currentPath: location.pathname,
});
return (
<SettingsHubShell vm={vm} icon={<FeatherClipboardList />}>
<Outlet />
</SettingsHubShell>
);
}