Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,17 +1,19 @@
import { redirect } from "react-router";
import { DefaultAdminRoles } from "~/application/dtos/shared/DefaultAdminRoles";
import { isAdminPermissionName } from "@hivegrid/db/admin-permissions";
import { DefaultPermission } from "~/application/dtos/shared/DefaultPermissions";
import { TenantUserStatus } from "~/application/enums/tenants/TenantUserStatus";
import { getPermissionName } from "~/utils/db/permissions/permissions.db.server";
import { findPermissionByUser, getUserRoleInAdmin, userHasPermission } from "~/utils/db/permissions/userRoles.db.server";
import { findPermissionByUser, userHasPermission } from "~/utils/db/permissions/userRoles.db.server";
import { getTenantMember } from "~/utils/db/tenants.db.server";
import { getIsSuperAdminByUserId } from "~/utils/loaders.middleware";
import { getUserInfo } from "~/utils/session.server";
import { getAuthUserWithoutPasswordById as getUser } from "@hivegrid/db/auth-boundary.server";
import { getTenantBillingReadOnlyState } from "~/utils/services/.server/billingStatusService";
import { getTenantDeletionReadOnlyState } from "~/utils/services/.server/tenantDeletionStatusService";
import { getHostRoutingContextFromRequest } from "~/utils/app/HostRouting.server";
import { requireAdminIdentityPermission } from "~/services/admin/admin-identity.server";
import { NOT_FOUND_ENVELOPE } from "~/utils/errors.server";
const OPERATOR_ADMIN_BYPASS_DESCRIPTION = "Operator admin tenant permission bypass";
const BILLING_READ_ONLY_MUTATION_ENVELOPE = { error: { code: "READ_ONLY", messageKey: "billing:status.readOnly" } };
const DELETION_READ_ONLY_MUTATION_ENVELOPE = { error: { code: "READ_ONLY", messageKey: "settings.privacy.deletion.readOnly" } };
function isMutatingRequest(request: Request): boolean {
return !["GET", "HEAD", "OPTIONS"].includes(request.method.toUpperCase());
@@ -22,34 +24,40 @@ export function isBillingReadOnlyBypassPath(requestUrl: string): boolean {
return /\/settings\/subscription\/?$/.test(pathname);
}
/**
* AK-P21 — during the tenant-deletion grace window the privacy area stays
* writable: admins must be able to withdraw the request and pull a GDPR
* export; users must be able to manage their account deletion.
*/
export function isDeletionReadOnlyBypassPath(requestUrl: string): boolean {
const pathname = new URL(requestUrl).pathname;
return /\/settings\/privacy(\/|$)/.test(pathname);
}
export async function assertTenantWritableForRequest(request: Request, tenantId: string | null) {
if (!tenantId || !isMutatingRequest(request) || isBillingReadOnlyBypassPath(request.url)) {
if (!tenantId || !isMutatingRequest(request)) {
return;
}
const billingState = await getTenantBillingReadOnlyState(tenantId);
if (billingState.readOnly) {
throw Response.json(BILLING_READ_ONLY_MUTATION_ENVELOPE, { status: 423 });
if (!isBillingReadOnlyBypassPath(request.url)) {
const billingState = await getTenantBillingReadOnlyState(tenantId);
if (billingState.readOnly) {
throw Response.json(BILLING_READ_ONLY_MUTATION_ENVELOPE, { status: 423 });
}
}
// AK-P21 deletion_pending read-only: reuse of the AK-P20 frozen mechanism.
if (!isDeletionReadOnlyBypassPath(request.url)) {
const deletionState = await getTenantDeletionReadOnlyState(tenantId);
if (deletionState.readOnly) {
throw Response.json(DELETION_READ_ONLY_MUTATION_ENVELOPE, { status: 423 });
}
}
}
export async function getUserPermission({ userId, permissionName, tenantId }: { userId: string; permissionName: string; tenantId?: string | null }) {
if (tenantId) {
const user = await getUser(userId);
const isOperatorAdmin = !!user?.admin || (await getIsSuperAdminByUserId(userId)) || !!(await getUserRoleInAdmin(userId, DefaultAdminRoles.SuperAdmin));
if (isOperatorAdmin) {
return {
permission: { id: "operator-admin-bypass", name: permissionName, description: OPERATOR_ADMIN_BYPASS_DESCRIPTION },
userPermission: permissionName,
};
}
}
const permission = await getPermissionName(permissionName);
if (!permission) {
return { permission, userPermission: undefined };
}
if (tenantId && (await getIsSuperAdminByUserId(userId))) {
return { permission, userPermission: permission.name };
}
// const userRoles = await getUserRoles(userId ?? undefined, tenantId ?? null);
// let userPermission: Permission | undefined = undefined;
// userRoles.forEach((userRole) => {
@@ -102,6 +110,13 @@ export function shapePermissionCheckResult({
}
export async function verifyUserHasPermission(request: Request, permissionName: DefaultPermission, tenantId: string | null = null) {
if (getHostRoutingContextFromRequest(request) === "admin") {
if (!isAdminPermissionName(permissionName)) {
throw Response.json(NOT_FOUND_ENVELOPE, { status: 404 });
}
await requireAdminIdentityPermission(request, permissionName);
return true;
}
// if (permissionName.startsWith("entity.")) {
// return true;
// }
@@ -112,15 +127,6 @@ export async function verifyUserHasPermission(request: Request, permissionName:
throw Error("Unauthorized");
}
await assertTenantWritableForRequest(request, tenantId);
if (tenantId) {
const user = await getUser(userInfo.userId);
const isOperatorAdmin =
!!user?.admin || (await getIsSuperAdminByUserId(userInfo.userId)) || !!(await getUserRoleInAdmin(userInfo.userId, DefaultAdminRoles.SuperAdmin));
if (isOperatorAdmin) {
shapePermissionCheckResult({ allowed: true, permissionName, tenantId });
return true;
}
}
const permission = await getPermissionName(permissionName);
if (!permission) {
shapePermissionCheckResult({ allowed: false, permissionName, tenantId, reason: "permission-denied" });