Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+103
@@ -0,0 +1,103 @@
|
||||
// VA-P23 · shared loader/action guard for the email-inbox module (mirrors
|
||||
// calendarAccess). The MODULE gate is the plan-gated `email-inbox` feature
|
||||
// (tenantHasModule). Visibility (M09 Block I): `email.read_own` sees only
|
||||
// mailboxes with ownerUserId = self, `email.read_all` sees every tenant mailbox,
|
||||
// `email.write` composes/sends over the own mailbox. 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 { EMAIL_INBOX_MODULE_KEY } from "./emailInboxRoutePaths";
|
||||
|
||||
/** Email-inbox atomic permissions (M09 Block I). */
|
||||
export const EMAIL_PERMISSIONS = {
|
||||
/** See mails of the user's OWN connected mailboxes (default tenant-user capability). */
|
||||
readOwn: "email.read_own",
|
||||
/** See every tenant mailbox's mails (tenant administration). */
|
||||
readAll: "email.read_all",
|
||||
/** Compose/send over the user's own connected mailbox. */
|
||||
write: "email.write",
|
||||
} as const;
|
||||
|
||||
export type EmailInboxRouteContext = {
|
||||
tenantId: string;
|
||||
userId: string;
|
||||
permissions: readonly string[];
|
||||
hasModule: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolve the email-inbox route context: auth + tenant + the email-inbox 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 loadEmailInboxContext({
|
||||
request,
|
||||
params,
|
||||
requireModule = false,
|
||||
}: {
|
||||
request: Request;
|
||||
params: Record<string, string | undefined>;
|
||||
requireModule?: boolean;
|
||||
}): Promise<EmailInboxRouteContext> {
|
||||
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: EMAIL_INBOX_MODULE_KEY }),
|
||||
getPermissionsByUser(userInfo.userId, tenantId),
|
||||
]);
|
||||
if (requireModule && !hasModule) {
|
||||
throw new CatalogError(foundationErrors.notFound, { module: EMAIL_INBOX_MODULE_KEY });
|
||||
}
|
||||
return { tenantId, userId: userInfo.userId, permissions, hasModule };
|
||||
}
|
||||
|
||||
/** True when the user may see EVERY tenant mailbox (read_all bundle). */
|
||||
export function canReadAllMailboxes(ctx: EmailInboxRouteContext): boolean {
|
||||
return ctx.permissions.includes(EMAIL_PERMISSIONS.readAll);
|
||||
}
|
||||
|
||||
/** True when the user may see at least their own mailboxes. */
|
||||
export function canReadOwnMailboxes(ctx: EmailInboxRouteContext): boolean {
|
||||
return ctx.permissions.includes(EMAIL_PERMISSIONS.readOwn) || canReadAllMailboxes(ctx);
|
||||
}
|
||||
|
||||
/** True when the user may compose/send over their own mailbox. */
|
||||
export function canWriteEmail(ctx: EmailInboxRouteContext): boolean {
|
||||
return ctx.permissions.includes(EMAIL_PERMISSIONS.write);
|
||||
}
|
||||
|
||||
/** Require any read capability; 404 if missing (A.5.3). */
|
||||
export function requireEmailRead(ctx: EmailInboxRouteContext): EmailInboxRouteContext {
|
||||
if (!canReadOwnMailboxes(ctx)) {
|
||||
throw new CatalogError(foundationErrors.notFound, { permission: EMAIL_PERMISSIONS.readOwn });
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/** Require the write capability; 404 if missing (A.5.3). */
|
||||
export function requireEmailWrite(ctx: EmailInboxRouteContext): EmailInboxRouteContext {
|
||||
if (!canWriteEmail(ctx)) {
|
||||
throw new CatalogError(foundationErrors.notFound, { permission: EMAIL_PERMISSIONS.write });
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Owner-check for mailbox-scoped resources (M09 Block I): with only read_own the
|
||||
* caller must own the mailbox; read_all lifts the restriction. Miss = 404.
|
||||
*/
|
||||
export function requireMailboxVisibility(ctx: EmailInboxRouteContext, mailboxOwnerUserId: string): EmailInboxRouteContext {
|
||||
if (ctx.userId === mailboxOwnerUserId || canReadAllMailboxes(ctx)) {
|
||||
return ctx;
|
||||
}
|
||||
throw new CatalogError(foundationErrors.notFound, { owner: "mismatch" });
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// VA-P23 · pure client-safe route-path builders for the email-inbox module.
|
||||
// Loaders build these and pass them into the VMs so the VMs stay routing-agnostic
|
||||
// (mirrors calendarRoutePaths). Unlike calendar, the email inbox has its OWN
|
||||
// plan-gated feature key (`email-inbox` in packages/entitlements) — the ticket
|
||||
// names the connector gate tenantHasModule('email_inbox'); the canonical key is
|
||||
// kebab-case per repo convention (documented deviation, VA-P23).
|
||||
|
||||
export const EMAIL_INBOX_MODULE_KEY = "email-inbox";
|
||||
|
||||
/** The inbox list. */
|
||||
export function emailInboxPath(tenantSlug: string): string {
|
||||
return `/${tenantSlug}/emails`;
|
||||
}
|
||||
|
||||
/** A single message's thread detail. */
|
||||
export function emailMessagePath(tenantSlug: string, messageId: string): string {
|
||||
return `/${tenantSlug}/emails/${messageId}`;
|
||||
}
|
||||
|
||||
/** The compose surface (new mail / reply / forward via query params). */
|
||||
export function emailComposePath(tenantSlug: string): string {
|
||||
return `/${tenantSlug}/emails/new`;
|
||||
}
|
||||
|
||||
/** The mailbox connect settings. */
|
||||
export function emailSettingsPath(tenantSlug: string): string {
|
||||
return `/${tenantSlug}/settings/integrations/email`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The OAuth callback URIs. NOT tenant-scoped (providers redirect to fixed URIs);
|
||||
* the signed `state` carries the tenant + user + provider.
|
||||
*/
|
||||
export const GMAIL_OAUTH_CALLBACK_PATH = "/integrations/email/google/oauth/callback";
|
||||
export const MICROSOFT_OAUTH_CALLBACK_PATH = "/integrations/email/microsoft/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 });
|
||||
}
|
||||
Reference in new issue
Block a user