feat(portal): replace mock data with real session-driven API calls #152

Merged
groombook-engineer[bot] merged 25 commits from feat/gro-203-rbac-super-user into main 2026-03-29 07:08:35 +00:00
2 changed files with 34 additions and 3 deletions
Showing only changes of commit 1c82a75a88 - Show all commits
+27 -3
View File
@@ -42,7 +42,7 @@ export const resolveStaffMiddleware: MiddlewareHandler<AppEnv> = async (
if (!manager) { if (!manager) {
return c.json({ error: "Forbidden: no staff records found" }, 403); return c.json({ error: "Forbidden: no staff records found" }, 403);
} }
c.set("staff", manager); c.set("staff", { ...manager, isSuperUser: true });
await next(); await next();
return; return;
} }
@@ -52,7 +52,7 @@ export const resolveStaffMiddleware: MiddlewareHandler<AppEnv> = async (
.from(staff) .from(staff)
.where(eq(staff.userId, devUserId)); .where(eq(staff.userId, devUserId));
if (row) { if (row) {
c.set("staff", row); c.set("staff", { ...row, isSuperUser: true });
await next(); await next();
return; return;
} }
@@ -68,7 +68,7 @@ export const resolveStaffMiddleware: MiddlewareHandler<AppEnv> = async (
403 403
); );
} }
c.set("staff", fallbackRow); c.set("staff", { ...fallbackRow, isSuperUser: true });
await next(); await next();
return; return;
} }
@@ -125,3 +125,27 @@ export function requireRole(
await next(); await next();
}; };
} }
/**
* Middleware that enforces the staff member is a super user.
* Must be applied after resolveStaffMiddleware and (typically) after requireRole.
*
* @example
* api.use("/staff/*", requireRole("manager"));
* api.use("/staff/*", requireSuperUser());
*/
export function requireSuperUser(): MiddlewareHandler<AppEnv> {
return async (c, next) => {
const staffRow = c.get("staff");
if (!staffRow) {
return c.json({ error: "Forbidden: staff record not resolved" }, 403);
}
if (!staffRow.isSuperUser) {
return c.json(
{ error: "Forbidden: super user privileges required" },
403
);
}
await next();
};
}
@@ -134,6 +134,13 @@
"when": 1774598400000, "when": 1774598400000,
"tag": "0018_backfill_staff_user_id", "tag": "0018_backfill_staff_user_id",
"breakpoints": true "breakpoints": true
},
{
"idx": 19,
"version": "7",
"when": 1774729055924,
"tag": "0019_concerned_sunfire",
"breakpoints": true
} }
] ]
} }