Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -0,0 +1,45 @@
import fs from "node:fs";
import path from "node:path";
import { describe, expect, test } from "vitest";
import { resolveRepoPath } from "~/utils/testing/repoPaths";
// AK-P16a · static authorization-boundary guard for the calendar mutation routes
// (DoD A.5 / DoD 3). Asserts every state-changing action runs the module/permission
// guard, the owner-check (where applicable) and CSRF validation BEFORE it reads the
// form body — so a missing module/permission/owner/CSRF can never reach a mutation.
const appRoot = resolveRepoPath("apps/web/app");
const mutationRoutes = [
"routes/app.$tenant/settings.integrations.calendar._index.tsx",
"routes/app.$tenant/settings.integrations.calendar.$id.tsx",
];
describe("calendar route authorization boundary", () => {
test("guards permission + CSRF before parsing the form body", () => {
for (const relativePath of mutationRoutes) {
const source = fs.readFileSync(path.join(appRoot, relativePath), "utf8");
const formDataAt = source.indexOf("await request.formData()");
expect(formDataAt, relativePath).toBeGreaterThanOrEqual(0);
const permissionAt = source.indexOf("requireCalendarPermission(ctx, CALENDAR_PERMISSIONS.connectOwn)");
expect(permissionAt, relativePath).toBeGreaterThanOrEqual(0);
expect(permissionAt, relativePath).toBeLessThan(formDataAt);
const csrfAt = source.indexOf("await validateCSRFToken(request)");
expect(csrfAt, relativePath).toBeGreaterThanOrEqual(0);
expect(csrfAt, relativePath).toBeLessThan(formDataAt);
}
});
test("detail route owner-checks the connection before mutating", () => {
const source = fs.readFileSync(path.join(appRoot, "routes/app.$tenant/settings.integrations.calendar.$id.tsx"), "utf8");
const ownerAt = source.indexOf("requireConnectionOwner(ctx, connection.userId)");
const formDataAt = source.indexOf("await request.formData()");
expect(ownerAt).toBeGreaterThanOrEqual(0);
// The action's owner-check (the second occurrence) precedes the form read.
const actionOwnerAt = source.indexOf("requireConnectionOwner(ctx, connection.userId)", ownerAt + 1);
expect(actionOwnerAt).toBeGreaterThanOrEqual(0);
expect(actionOwnerAt).toBeLessThan(formDataAt);
});
});
@@ -0,0 +1,85 @@
// AK-P16a · shared loader/action guard for the calendar module (mirrors
// integrationsAccess / taskAccess). Calendar is an Apps-Engine integration, so the
// MODULE gate reuses the `integrations` feature (tenantHasModule) — there is no
// separate plan-gated "calendar" feature (M25 Block I: connecting your own
// calendar is a default tenant-user capability). The PER-USER capability is gated
// by the `calendar.connect_own` permission; `calendar.admin` is tenant-wide
// oversight. Module-off renders a locked empty VM on GET and 404s on write
// (Bauprinzip A.5.3); a permission miss is also a 404, never a 403.
import { CatalogError, foundationErrors } from "@hivegrid/foundation";
import { requireAuth } from "~/utils/loaders.middleware";
import { getTenantIdFromUrl } from "~/utils/services/.server/urlService";
import { getUserInfo } from "~/utils/session.server";
import { tenantHasModule } from "~/utils/connector/tenantConnector.server";
import { getPermissionsByUser } from "~/utils/db/permissions/userRoles.db.server";
import { INTEGRATIONS_MODULE_KEY } from "~/utils/integrations/integrationsRoutePaths";
/** Calendar atomic permissions (M25 Block I). */
export const CALENDAR_PERMISSIONS = {
/** Connect/manage your OWN calendar connection (default tenant-user capability). */
connectOwn: "calendar.connect_own",
/** Tenant-wide oversight + force-disconnect on user offboarding. */
admin: "calendar.admin",
} as const;
export type CalendarRouteContext = {
tenantId: string;
userId: string;
permissions: readonly string[];
hasModule: boolean;
};
/**
* Resolve the calendar route context: auth + tenant + the integrations module gate
* + the user's permissions. With `requireModule` a module-off tenant 404s (write
* paths); GET paths can render a locked empty VM from `hasModule === false`.
*/
export async function loadCalendarContext({
request,
params,
requireModule = false,
}: {
request: Request;
params: Record<string, string | undefined>;
requireModule?: boolean;
}): Promise<CalendarRouteContext> {
await requireAuth({ request, params });
const [tenantId, userInfo] = await Promise.all([getTenantIdFromUrl(params), getUserInfo(request)]);
if (!tenantId || !userInfo.userId) {
throw new CatalogError(foundationErrors.notFound);
}
const [hasModule, permissions] = await Promise.all([
tenantHasModule({ tenantId, userId: userInfo.userId, moduleKey: INTEGRATIONS_MODULE_KEY }),
getPermissionsByUser(userInfo.userId, tenantId),
]);
if (requireModule && !hasModule) {
throw new CatalogError(foundationErrors.notFound, { module: INTEGRATIONS_MODULE_KEY });
}
return { tenantId, userId: userInfo.userId, permissions, hasModule };
}
/** True if the user holds `permission` or the broader `calendar.admin` bundle. */
export function calendarHasPermission(ctx: CalendarRouteContext, permission: string): boolean {
return ctx.permissions.includes(permission) || ctx.permissions.includes(CALENDAR_PERMISSIONS.admin);
}
/** Require a calendar.* permission (admin-aware); 404 if missing (A.5.3). */
export function requireCalendarPermission(ctx: CalendarRouteContext, permission: string): CalendarRouteContext {
if (!calendarHasPermission(ctx, permission)) {
throw new CatalogError(foundationErrors.notFound, { permission });
}
return ctx;
}
/**
* Owner-check for connection-scoped routes (leak-protection, DoD 3): only the
* owning user may see/manage a connection's external event details — UNLESS the
* caller holds `calendar.admin` (tenant oversight). A miss is a 404, not a 403.
*/
export function requireConnectionOwner(ctx: CalendarRouteContext, connectionUserId: string): CalendarRouteContext {
if (ctx.userId === connectionUserId || ctx.permissions.includes(CALENDAR_PERMISSIONS.admin)) {
return ctx;
}
throw new CatalogError(foundationErrors.notFound, { owner: "mismatch" });
}
@@ -0,0 +1,33 @@
// AK-P16a · pure client-safe route-path builders for the calendar module. Loaders
// build these and pass them into the VMs so the VMs stay routing-agnostic (mirrors
// integrationsRoutePaths). Calendar reuses the `integrations` tenant-connector
// module key (calendar is an Apps-Engine integration; see calendarAccess.server).
export { INTEGRATIONS_MODULE_KEY as CALENDAR_MODULE_KEY } from "~/utils/integrations/integrationsRoutePaths";
/** The calendar grid view (all sources). */
export function calendarViewPath(tenantSlug: string): string {
return `/${tenantSlug}/calendar`;
}
/** The calendar connections settings list. */
export function calendarConnectionsPath(tenantSlug: string): string {
return `/${tenantSlug}/settings/integrations/calendar`;
}
/** A single connection's detail (selected calendars, status, conflict log). */
export function calendarConnectionDetailPath(tenantSlug: string, connectionId: string): string {
return `/${tenantSlug}/settings/integrations/calendar/${connectionId}`;
}
/**
* The OAuth callback URI. NOT tenant-scoped: EXT-10 registered exactly
* `/integrations/google/oauth/callback` at the app root (Google redirects here);
* the signed `state` carries the tenant + user.
*/
export const GOOGLE_OAUTH_CALLBACK_PATH = "/integrations/google/oauth/callback";
/** 404 helper (Bauprinzip A.5.3 — permission/owner miss renders 404, not 403). */
export function notFoundResponse(): Response {
return new Response("Not Found", { status: 404 });
}