mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-16 10:50:38 +09:00
Fix feedback review findings
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
c0d0d03bce
commit
d12e3e3d1a
7 changed files with 200 additions and 86 deletions
|
|
@ -116,6 +116,13 @@ export function issueRoutes(db: Db, storage: StorageService) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function actorCanAccessCompany(req: Request, companyId: string) {
|
||||
if (req.actor.type === "none") return false;
|
||||
if (req.actor.type === "agent") return req.actor.companyId === companyId;
|
||||
if (req.actor.source === "local_implicit" || req.actor.isInstanceAdmin) return true;
|
||||
return (req.actor.companyIds ?? []).includes(companyId);
|
||||
}
|
||||
|
||||
function canCreateAgentsLegacy(agent: { permissions: Record<string, unknown> | null | undefined; role: string }) {
|
||||
if (agent.role === "ceo") return true;
|
||||
if (!agent.permissions || typeof agent.permissions !== "object") return false;
|
||||
|
|
@ -1538,31 +1545,30 @@ export function issueRoutes(db: Db, storage: StorageService) {
|
|||
|
||||
router.get("/feedback-traces/:traceId", async (req, res) => {
|
||||
const traceId = req.params.traceId as string;
|
||||
const trace = await feedback.getFeedbackTraceById(traceId, parseBooleanQuery(req.query.includePayload) || req.query.includePayload === undefined);
|
||||
if (!trace) {
|
||||
res.status(404).json({ error: "Feedback trace not found" });
|
||||
return;
|
||||
}
|
||||
assertCompanyAccess(req, trace.companyId);
|
||||
if (req.actor.type !== "board") {
|
||||
res.status(403).json({ error: "Only board users can view feedback traces" });
|
||||
return;
|
||||
}
|
||||
const includePayload = parseBooleanQuery(req.query.includePayload) || req.query.includePayload === undefined;
|
||||
const trace = await feedback.getFeedbackTraceById(traceId, includePayload);
|
||||
if (!trace || !actorCanAccessCompany(req, trace.companyId)) {
|
||||
res.status(404).json({ error: "Feedback trace not found" });
|
||||
return;
|
||||
}
|
||||
res.json(trace);
|
||||
});
|
||||
|
||||
router.get("/feedback-traces/:traceId/bundle", async (req, res) => {
|
||||
const traceId = req.params.traceId as string;
|
||||
const bundle = await feedback.getFeedbackTraceBundle(traceId);
|
||||
if (!bundle) {
|
||||
res.status(404).json({ error: "Feedback trace not found" });
|
||||
return;
|
||||
}
|
||||
assertCompanyAccess(req, bundle.companyId);
|
||||
if (req.actor.type !== "board") {
|
||||
res.status(403).json({ error: "Only board users can view feedback trace bundles" });
|
||||
return;
|
||||
}
|
||||
const bundle = await feedback.getFeedbackTraceBundle(traceId);
|
||||
if (!bundle || !actorCanAccessCompany(req, bundle.companyId)) {
|
||||
res.status(404).json({ error: "Feedback trace not found" });
|
||||
return;
|
||||
}
|
||||
res.json(bundle);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue