mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-15 18:30:39 +09:00
31 lines
778 B
TypeScript
31 lines
778 B
TypeScript
|
|
import type { Request } from "express";
|
||
|
|
import { forbidden } from "../errors.js";
|
||
|
|
|
||
|
|
export function assertBoard(req: Request) {
|
||
|
|
if (req.actor.type !== "board") {
|
||
|
|
throw forbidden("Board access required");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export function assertCompanyAccess(req: Request, companyId: string) {
|
||
|
|
if (req.actor.type === "agent" && req.actor.companyId !== companyId) {
|
||
|
|
throw forbidden("Agent key cannot access another company");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getActorInfo(req: Request) {
|
||
|
|
if (req.actor.type === "agent") {
|
||
|
|
return {
|
||
|
|
actorType: "agent" as const,
|
||
|
|
actorId: req.actor.agentId ?? "unknown-agent",
|
||
|
|
agentId: req.actor.agentId ?? null,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
return {
|
||
|
|
actorType: "user" as const,
|
||
|
|
actorId: req.actor.userId ?? "board",
|
||
|
|
agentId: null,
|
||
|
|
};
|
||
|
|
}
|