mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-22 11:54:35 +01:00
fix(dashboard): scope areas and responsibilities to each user (#22513)
This commit is contained in:
1 parent
558dbb0132
commit
856f14e507
68 files changed
+2708
-559
No files matched your search
@@ -212,6 +212,7 @@ describe("activity routes", () => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(mockAgentActionAuditService.list).toHaveBeenCalledWith({
|
||||
companyId: "company-1",
|
||||
dashboardUserId: "user-1",
|
||||
actorScope: "all",
|
||||
limit: 50,
|
||||
caseReadCondition,
|
||||
@@ -261,6 +262,7 @@ describe("activity routes", () => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(mockAgentActionAuditService.list).toHaveBeenCalledWith({
|
||||
companyId: "company-1",
|
||||
dashboardUserId: "user-1",
|
||||
actorScope: "all",
|
||||
actorType: "system",
|
||||
limit: 50,
|
||||
@@ -284,6 +286,7 @@ describe("activity routes", () => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(mockActivityService.list).toHaveBeenCalledWith({
|
||||
companyId: "company-1",
|
||||
dashboardUserId: "user-1",
|
||||
agentId: undefined,
|
||||
entityType: undefined,
|
||||
entityId: undefined,
|
||||
@@ -304,6 +307,7 @@ describe("activity routes", () => {
|
||||
expect(res.status).toBe(200);
|
||||
expect(mockActivityService.list).toHaveBeenCalledWith({
|
||||
companyId: "company-1",
|
||||
dashboardUserId: "user-1",
|
||||
agentId: undefined,
|
||||
entityType: "issue",
|
||||
entityId: undefined,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import express from "express";
|
||||
import { eq } from "drizzle-orm";
|
||||
import request from "supertest";
|
||||
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
@@ -214,6 +215,31 @@ describeEmbeddedPostgres("issue access grant and locked edge routes", { concurre
|
||||
};
|
||||
}
|
||||
|
||||
it("protects personal dashboard conversations from break-glass and title writes by teammates", async () => {
|
||||
const fixture = await seedFixture();
|
||||
const issueId = fixture.privateIssueId;
|
||||
await db.update(issues).set({
|
||||
originKind: "responsibility_dashboard",
|
||||
originId: fixture.ownerId,
|
||||
projectId: null,
|
||||
}).where(eq(issues.id, issueId));
|
||||
const owner = await createApp(db, boardActor(fixture.companyId, fixture.ownerId));
|
||||
const admin = await createApp(db, boardActor(fixture.companyId, fixture.adminId));
|
||||
const member = await createApp(db, boardActor(fixture.companyId, fixture.memberId));
|
||||
|
||||
await request(admin).get(`/api/issues/${issueId}?breakGlass=true&view=core`).expect(404);
|
||||
await request(member).put(`/api/issues/${issueId}/title`).send({ title: "Another title" }).expect(404);
|
||||
await request(member).put(`/api/issues/${issueId}/title`).send({
|
||||
title: "Another title", onlyIfProvisional: true,
|
||||
}).expect(404);
|
||||
await request(admin).post(`/api/issues/${issueId}/admin/force-release`).expect(404);
|
||||
const original = await request(owner).get(`/api/issues/${issueId}?view=core`).expect(200);
|
||||
expect(original.body.title).toBe("Confidential root");
|
||||
const renamed = await request(owner).put(`/api/issues/${issueId}/title`).send({ title: "My dashboard" }).expect(200);
|
||||
expect(renamed.body.title).toBe("My dashboard");
|
||||
expect(await db.select().from(activityLog).where(eq(activityLog.action, "issue.break_glass_read"))).toEqual([]);
|
||||
});
|
||||
|
||||
it("requires explicit owner/admin break-glass and records both audit evidence and an owner-visible notice", async () => {
|
||||
const fixture = await seedFixture();
|
||||
const adminApp = await createApp(db, boardActor(fixture.companyId, fixture.adminId));
|
||||
|
||||
@@ -240,12 +240,11 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
expect(created.status).toBe(201);
|
||||
expect(created.body).toMatchObject({ ownerUserId: OWNER, status: "active" });
|
||||
|
||||
// A named owner still wins, and a run that works for no person must name one.
|
||||
// A caller-supplied owner cannot change the verified dashboard.
|
||||
const other = await request(forOwner).get(`/api/companies/${company.id}/responsibilities?ownerUserId=other-user`);
|
||||
expect(other.body.ownerUserId).toBe("other-user");
|
||||
expect(other.status).toBe(404);
|
||||
const unbound = await request(createApp(db, agentActor(company.id, agent.id))).get(`/api/companies/${company.id}/responsibilities`);
|
||||
expect(unbound.status).toBe(422);
|
||||
expect(unbound.body.error).toContain("this run works for no person");
|
||||
expect(unbound.status).toBe(403);
|
||||
});
|
||||
|
||||
it("refuses a half-filled bar, and derives status from the metric", async () => {
|
||||
@@ -367,68 +366,22 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
expect(halfAgain.status).toBe(422);
|
||||
});
|
||||
|
||||
it("lets agents only propose, and confirming activates a proposed area in the same step", async () => {
|
||||
it("keeps proposals inside the directing person's dashboard and activates their area on confirmation", async () => {
|
||||
await enable();
|
||||
const company = await seedCompany();
|
||||
const guide = await seedAgent(company.id);
|
||||
const agentApp = createApp(db, agentActor(company.id, guide.id));
|
||||
const boardApp = createApp(db, localBoardActor());
|
||||
|
||||
const area = await request(agentApp).post(`/api/companies/${company.id}/responsibility-areas`).send({ title: "Fundraising", status: "active" });
|
||||
expect(area.status).toBe(201);
|
||||
expect(area.body).toMatchObject({ status: "proposed", source: "onboarding", proposedByAgentId: guide.id });
|
||||
|
||||
expect((await request(agentApp).post(`/api/companies/${company.id}/responsibilities`).send({ title: "Pipeline", ...METRIC })).status).toBe(422);
|
||||
expect((await request(agentApp).post(`/api/companies/${company.id}/responsibilities`)
|
||||
.send({ title: "Pipeline", ...METRIC, ownerUserId: "stranger" })).status).toBe(404);
|
||||
// An agent always proposes the whole bar: a title alone, or the sentence alone, is refused.
|
||||
expect((await request(agentApp).post(`/api/companies/${company.id}/responsibilities`)
|
||||
.send({ title: "Pipeline", ownerUserId: OWNER })).status).toBe(400);
|
||||
expect((await request(agentApp).post(`/api/companies/${company.id}/responsibilities`)
|
||||
.send({ title: "Pipeline", ownerUserId: OWNER, standard: METRIC.standard })).status).toBe(400);
|
||||
expect((await request(agentApp).post(`/api/companies/${company.id}/responsibilities`)
|
||||
.send({ title: "Pipeline", ownerUserId: OWNER, standard: METRIC.standard, metricName: METRIC.metricName })).status).toBe(400);
|
||||
|
||||
const proposed = await request(agentApp).post(`/api/companies/${company.id}/responsibilities`).send({
|
||||
title: "Pipeline",
|
||||
...METRIC,
|
||||
ownerUserId: OWNER,
|
||||
areaId: area.body.id,
|
||||
status: "active",
|
||||
evidence: "Three pipeline reviews on the calendar every week",
|
||||
});
|
||||
expect(proposed.status).toBe(201);
|
||||
expect(proposed.body).toMatchObject({ status: "proposed", source: "onboarding", proposedByAgentId: guide.id, confirmedAt: null, areaId: area.body.id });
|
||||
|
||||
const listed = await request(agentApp).get(`/api/companies/${company.id}/responsibilities?ownerUserId=${OWNER}`);
|
||||
expect(listed.body.proposed.map((row: { id: string }) => row.id)).toEqual([proposed.body.id]);
|
||||
// A proposed area a returned responsibility references is included.
|
||||
expect(listed.body.areas.map((row: { id: string; status: string }) => [row.id, row.status])).toEqual([[area.body.id, "proposed"]]);
|
||||
|
||||
expect((await request(agentApp).patch(`/api/responsibilities/${proposed.body.id}`).send({ status: "active" })).status).toBe(403);
|
||||
const edited = await request(agentApp).patch(`/api/responsibilities/${proposed.body.id}`).send({ title: "Deal pipeline" });
|
||||
expect(edited.status).toBe(200);
|
||||
|
||||
const confirmed = await request(boardApp).patch(`/api/responsibilities/${proposed.body.id}`).send({ status: "active" });
|
||||
expect(confirmed.status).toBe(200);
|
||||
expect(confirmed.body.confirmedAt).not.toBeNull();
|
||||
const [areaRow] = await db.select().from(responsibilityAreas).where(eq(responsibilityAreas.id, area.body.id));
|
||||
expect(areaRow?.status).toBe("active");
|
||||
const logged = await actions(company.id);
|
||||
expect(logged).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({ action: "responsibility_area.created", entityId: area.body.id }),
|
||||
expect.objectContaining({ action: "responsibility_area.activated", entityId: area.body.id }),
|
||||
]));
|
||||
|
||||
// Once confirmed, the agent can no longer edit it (beyond the metric) and cannot delete it.
|
||||
expect((await request(agentApp).patch(`/api/responsibilities/${proposed.body.id}`).send({ title: "x" })).status).toBe(403);
|
||||
expect((await request(agentApp).delete(`/api/responsibilities/${proposed.body.id}`)).status).toBe(403);
|
||||
|
||||
const dismissible = await request(agentApp).post(`/api/companies/${company.id}/responsibilities`)
|
||||
.send({ title: "Portfolio", ...METRIC, ownerUserId: OWNER });
|
||||
const dismissed = await request(agentApp).patch(`/api/responsibilities/${dismissible.body.id}`).send({ status: "dismissed" });
|
||||
expect(dismissed.status).toBe(200);
|
||||
expect(dismissed.body.status).toBe("dismissed");
|
||||
const agent = await actingAgent(company.id, guide.id);
|
||||
const unbound = createApp(db, agentActor(company.id, guide.id));
|
||||
const board = createApp(db, localBoardActor());
|
||||
const path = `/api/companies/${company.id}/responsibilities`;
|
||||
const areas = `/api/companies/${company.id}/responsibility-areas`;
|
||||
await request(unbound).post(areas).send({ title: "Fundraising" }).expect(403);
|
||||
await request(unbound).post(path).send({ title: "Pipeline", ...METRIC, ownerUserId: OWNER }).expect(403);
|
||||
const area = (await request(agent).post(areas).send({ title: "Fundraising", status: "proposed" }).expect(201)).body;
|
||||
const item = (await request(agent).post(path).send({ title: "Pipeline", ...METRIC, areaId: area.id, status: "proposed" }).expect(201)).body;
|
||||
expect((await request(board).get(path)).body.proposed.map((r: Created) => r.id)).toEqual([item.id]);
|
||||
await request(board).patch(`/api/responsibilities/${item.id}`).send({ status: "active" }).expect(200);
|
||||
expect((await request(board).get(areas)).body[0]).toMatchObject({ id: area.id, status: "active" });
|
||||
});
|
||||
|
||||
it("lets only the running or assigned agent report the metric on an active responsibility", async () => {
|
||||
@@ -474,16 +427,16 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
expect((await actions(company.id)).some((entry) => entry.action === "responsibility.updated")).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps board users to their own responsibilities unless they administer the company", async () => {
|
||||
it("keeps board users to their own responsibilities including company administrators", async () => {
|
||||
await enable();
|
||||
const company = await seedCompany();
|
||||
const ownerApp = createApp(db, localBoardActor());
|
||||
const area = await createResponsibility(ownerApp, company.id);
|
||||
const operatorApp = createApp(db, sessionBoardActor(company.id, "other-user"));
|
||||
expect((await request(operatorApp).get(`/api/responsibilities/${area.id}`)).status).toBe(200);
|
||||
expect((await request(operatorApp).patch(`/api/responsibilities/${area.id}`).send({ title: "Mine now" })).status).toBe(403);
|
||||
expect((await request(operatorApp).get(`/api/responsibilities/${area.id}`)).status).toBe(404);
|
||||
expect((await request(operatorApp).patch(`/api/responsibilities/${area.id}`).send({ title: "Mine now" })).status).toBe(404);
|
||||
expect((await request(operatorApp).post(`/api/companies/${company.id}/responsibilities`)
|
||||
.send({ title: "For someone else", ...METRIC, ownerUserId: OWNER })).status).toBe(403);
|
||||
.send({ title: "For someone else", ...METRIC, ownerUserId: OWNER })).status).toBe(404);
|
||||
const own = await createResponsibility(operatorApp, company.id, { title: "Ops" });
|
||||
expect(own.ownerUserId).toBe("other-user");
|
||||
});
|
||||
@@ -519,7 +472,7 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
expect((await request(boardApp).patch(`/api/responsibilities/${area.id}`).send({ areaId: otherArea.body.id })).status).toBe(404);
|
||||
expect((await request(boardApp).post(`/api/companies/${company.id}/responsibilities`)
|
||||
.send({ title: "x", ...METRIC, runByAgentId: otherAgent.id })).status).toBe(404);
|
||||
expect((await request(boardApp).patch(`/api/responsibility-areas/${otherArea.body.id}`).send({ title: "Mine" })).status).toBe(200);
|
||||
expect((await request(boardApp).patch(`/api/responsibility-areas/${otherArea.body.id}`).send({ title: "Mine" })).status).toBe(404);
|
||||
expect((await request(createApp(db, sessionBoardActor(company.id, OWNER, "owner")))
|
||||
.patch(`/api/responsibility-areas/${otherArea.body.id}`).send({ title: "Mine" })).status).toBe(404);
|
||||
expect(await db.select().from(responsibilityLinks).where(eq(responsibilityLinks.companyId, company.id))).toHaveLength(0);
|
||||
@@ -622,8 +575,7 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
const guide = await seedAgent(company.id);
|
||||
const agentLookup = await request(createApp(db, agentActor(company.id, guide.id)))
|
||||
.get(`/api/companies/${company.id}/responsibility-links/lookup?issueId=${task.id}`);
|
||||
expect(agentLookup.status).toBe(200);
|
||||
expect(agentLookup.body.responsibilities).toHaveLength(2);
|
||||
expect(agentLookup.status).toBe(403);
|
||||
});
|
||||
|
||||
it("manages areas: idempotent create, board-only edits, delete keeps responsibilities", async () => {
|
||||
@@ -641,17 +593,17 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
expect(same.status).toBe(200);
|
||||
expect(same.body.id).toBe(created.body.id);
|
||||
const agentSame = await request(agentApp).post(areasPath).send({ title: "FUNDRAISING" });
|
||||
expect(agentSame.status).toBe(200);
|
||||
expect(agentSame.body).toMatchObject({ id: created.body.id, status: "active" });
|
||||
const customers = await request(agentApp).post(areasPath).send({ title: "Customers" });
|
||||
expect(agentSame.status).toBe(403);
|
||||
const customers = await request(boardApp).post(areasPath).send({ title: "Customers", status: "proposed" });
|
||||
expect(customers.body.status).toBe("proposed");
|
||||
|
||||
expect((await request(agentApp).patch(`/api/responsibility-areas/${created.body.id}`).send({ title: "x" })).status).toBe(403);
|
||||
expect((await request(agentApp).delete(`/api/responsibility-areas/${created.body.id}`)).status).toBe(403);
|
||||
expect((await request(createApp(db, sessionBoardActor(company.id, "viewer", "viewer"))).post(areasPath).send({ title: "Viewers" })).status).toBe(403);
|
||||
// Any board user with write access manages areas: they have no owner.
|
||||
// The owner alone can activate the area.
|
||||
const operatorApp = createApp(db, sessionBoardActor(company.id, "other-user"));
|
||||
expect((await request(operatorApp).patch(`/api/responsibility-areas/${customers.body.id}`).send({ status: "active", sortOrder: 2 })).status).toBe(200);
|
||||
expect((await request(operatorApp).patch(`/api/responsibility-areas/${customers.body.id}`).send({ status: "active", sortOrder: 2 })).status).toBe(404);
|
||||
await request(boardApp).patch(`/api/responsibility-areas/${customers.body.id}`).send({ status: "active", sortOrder: 2 }).expect(200);
|
||||
|
||||
const clash = await request(boardApp).patch(`/api/responsibility-areas/${customers.body.id}`).send({ title: "fundraising" });
|
||||
expect(clash.status).toBe(409);
|
||||
@@ -1049,7 +1001,7 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
expect(unfiled.body.unfiled).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("may not change what the person could not, and stays propose-only without a person", async () => {
|
||||
it("may not change what the person could not, and needs a directing person for proposals", async () => {
|
||||
await enable();
|
||||
const company = await seedCompany();
|
||||
const agent = await seedAgent(company.id);
|
||||
@@ -1058,21 +1010,15 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
|
||||
// An operator may not manage the owner's responsibilities, so neither may an agent acting for one.
|
||||
const forOperator = await actingAgent(company.id, agent.id, "other-user", "operator");
|
||||
expect((await request(forOperator).patch(`/api/responsibilities/${mine.id}`).send({ title: "x" })).status).toBe(403);
|
||||
expect((await request(forOperator).post(`/api/responsibilities/${mine.id}/file`).send({ items: [{ kind: "routine", id: randomUUID() }], moveFrom: "all" })).status).toBe(403);
|
||||
expect((await request(forOperator).patch(`/api/responsibilities/${mine.id}`).send({ title: "x" })).status).toBe(404);
|
||||
expect((await request(forOperator).post(`/api/responsibilities/${mine.id}/file`).send({ items: [{ kind: "routine", id: randomUUID() }], moveFrom: "all" })).status).toBe(404);
|
||||
|
||||
const alone = createApp(db, agentActor(company.id, agent.id));
|
||||
expect((await request(alone).patch(`/api/responsibility-areas/${randomUUID()}`).send({ title: "x" })).status).toBe(404);
|
||||
const area = await request(board).post(`/api/companies/${company.id}/responsibility-areas`).send({ title: "People" });
|
||||
expect((await request(alone).patch(`/api/responsibility-areas/${area.body.id}`).send({ title: "x" })).status).toBe(403);
|
||||
const proposal = await request(alone).post(`/api/companies/${company.id}/responsibilities`).send({ title: "Ops", ownerUserId: OWNER, ...METRIC });
|
||||
expect(proposal.body.status).toBe("proposed");
|
||||
// Filing under its proposal works as with /links (what create_responsibility's fileItems does); moving does not.
|
||||
const routine = await db.insert(routines).values({ companyId: company.id, title: "Weekly ops" }).returning().then((r) => r[0]!);
|
||||
const filed = await request(alone).post(`/api/responsibilities/${proposal.body.id}/file`).send({ items: [{ kind: "routine", id: routine.id }] });
|
||||
expect(filed.status).toBe(200);
|
||||
expect(filed.headers["x-paperclip-dashboard-version"]).toBeUndefined();
|
||||
expect((await request(alone).post(`/api/responsibilities/${proposal.body.id}/file`).send({ items: [{ kind: "routine", id: routine.id }], moveFrom: mine.id })).status).toBe(403);
|
||||
expect(proposal.status).toBe(403);
|
||||
});
|
||||
|
||||
it("does not borrow the authority of a person someone else named, or of the company default", async () => {
|
||||
@@ -1097,7 +1043,7 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
expect((await request(app).post(`/api/companies/${company.id}/responsibilities`).send({ title: "Ops" })).status).toBe(400);
|
||||
}
|
||||
const proposal = await request(noTask).post(`/api/companies/${company.id}/responsibilities`).send({ title: "Ops", ...METRIC });
|
||||
expect(proposal.body).toMatchObject({ ownerUserId: OWNER, status: "proposed" });
|
||||
expect(proposal.status).toBe(403);
|
||||
const [row] = await db.select().from(responsibilities).where(eq(responsibilities.id, mine.id));
|
||||
expect(row?.status).toBe("active");
|
||||
});
|
||||
@@ -1248,30 +1194,12 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
expect(areaRow?.description).toBe("Who we hire");
|
||||
});
|
||||
|
||||
it("reports no Undo for a shared area's new description, and Undo of a delete brings the description back", async () => {
|
||||
it("restores the private area description after a confirmed deletion", async () => {
|
||||
await enable();
|
||||
const company = await seedCompany();
|
||||
const agent = await seedAgent(company.id);
|
||||
const app = await actingAgent(company.id, agent.id);
|
||||
const board = createApp(db, localBoardActor());
|
||||
const shared = await request(board).post(`/api/companies/${company.id}/responsibility-areas`).send({ title: "People", description: "Who we hire" });
|
||||
await createResponsibility(board, company.id, { title: "Hiring", areaId: shared.body.id });
|
||||
// The other person's responsibility there is only proposed; the area is still shared.
|
||||
const other = await createResponsibility(board, company.id, { title: "Onboarding", areaId: shared.body.id, ownerUserId: "other-user" });
|
||||
await db.update(responsibilities).set({ status: "proposed" }).where(eq(responsibilities.id, other.id));
|
||||
const before = await latestVersion(company.id);
|
||||
const described = await request(app).patch(`/api/responsibility-areas/${shared.body.id}`).send({ description: "Hiring and onboarding" });
|
||||
expect(described.status).toBe(200);
|
||||
expect(described.headers["x-paperclip-dashboard-version"]).toBeUndefined();
|
||||
// No version is saved, so no Dashboard offers an Undo that would leave the description as it is.
|
||||
expect((await latestVersion(company.id))?.id).toBe(before?.id);
|
||||
// Nor for a shared area's status change Undo cannot reverse, such as confirming a proposed area.
|
||||
await db.update(responsibilityAreas).set({ status: "proposed" }).where(eq(responsibilityAreas.id, shared.body.id));
|
||||
const confirmed = await request(app).patch(`/api/responsibility-areas/${shared.body.id}`).send({ status: "active" });
|
||||
expect(confirmed.status).toBe(200);
|
||||
expect(confirmed.headers["x-paperclip-dashboard-version"]).toBeUndefined();
|
||||
expect((await latestVersion(company.id))?.id).toBe(before?.id);
|
||||
|
||||
const mine = await request(board).post(`/api/companies/${company.id}/responsibility-areas`).send({ title: "Money", description: "Cash and runway" });
|
||||
await createResponsibility(board, company.id, { title: "Runway", areaId: mine.body.id });
|
||||
const [card] = await db.insert(issueThreadInteractions).values({
|
||||
@@ -1352,7 +1280,7 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
// An agent acting for an operator may not change the owner's active responsibility: no area is left behind.
|
||||
const refused = await request(await actingAgent(company.id, agent.id, "other-user", "operator"))
|
||||
.patch(`/api/responsibilities/${created.body.id}`).send({ areaTitle: "Elsewhere" });
|
||||
expect(refused.status).toBe(403);
|
||||
expect(refused.status).toBe(404);
|
||||
expect(await db.select().from(responsibilityAreas).where(eq(responsibilityAreas.title, "Elsewhere"))).toHaveLength(0);
|
||||
expect((await request(await actingAgent(company.id, agent.id)).patch(`/api/responsibilities/${created.body.id}`)
|
||||
.send({ areaTitle: "People", areaId: people!.id })).status).toBe(422);
|
||||
@@ -1374,14 +1302,14 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
expect(deleted.status).toBe(200);
|
||||
});
|
||||
|
||||
it("saves a version for everyone whose responsibilities an area delete moves", async () => {
|
||||
it("saves the moved responsibilities in the owner’s history", async () => {
|
||||
await enable();
|
||||
const company = await seedCompany();
|
||||
const agent = await seedAgent(company.id);
|
||||
const board = createApp(db, localBoardActor());
|
||||
const from = await request(board).post(`/api/companies/${company.id}/responsibility-areas`).send({ title: "Money" });
|
||||
const to = await request(board).post(`/api/companies/${company.id}/responsibility-areas`).send({ title: "Finance" });
|
||||
await createResponsibility(board, company.id, { title: "Runway", areaId: from.body.id, ownerUserId: "other-user" });
|
||||
await createResponsibility(board, company.id, { title: "Runway", areaId: from.body.id });
|
||||
const chat = await db.insert(issues).values({ companyId: company.id, title: "Chat", status: "in_progress", priority: "medium" }).returning().then((r) => r[0]!);
|
||||
const [card] = await db.insert(issueThreadInteractions).values({
|
||||
companyId: company.id, issueId: chat.id, kind: "request_confirmation", status: "accepted", createdByAgentId: agent.id,
|
||||
@@ -1391,7 +1319,7 @@ describeEmbeddedPostgres("responsibility routes", () => {
|
||||
const removed = await request(await actingAgent(company.id, agent.id))
|
||||
.delete(`/api/responsibility-areas/${from.body.id}?confirmationId=${card!.id}&moveResponsibilitiesTo=${to.body.id}`);
|
||||
expect(removed.status).toBe(200);
|
||||
expect(await latestVersion(company.id, "other-user")).toMatchObject({ cause: "change_set", actorAgentId: agent.id });
|
||||
expect(await latestVersion(company.id, "other-user")).toBeNull();
|
||||
// The response names the acting person's version, not the other owner's.
|
||||
expect(removed.headers["x-paperclip-dashboard-owner"]).toBe(OWNER);
|
||||
expect(removed.headers["x-paperclip-dashboard-version"]).toBe((await latestVersion(company.id))?.id);
|
||||
|
||||
@@ -274,14 +274,14 @@ describeEmbeddedPostgres("automation conversations and standing checks", () => {
|
||||
expect(started.body.details?.code ?? started.body.code).toBe("routine_from_task_private");
|
||||
expect(await db.select().from(issues).where(eq(issues.originId, privateId))).toHaveLength(0);
|
||||
const [open] = await db.select().from(issues).where(eq(issues.id, (await start(seeded, seeded.tasks.weekly.id, { agentId: seeded.agents.analyst.id })).body.conversation.issueId));
|
||||
expect(open).toMatchObject({ visibility: "open" });
|
||||
expect(open).toMatchObject({ visibility: "private", responsibleUserId: OWNER });
|
||||
});
|
||||
|
||||
it("lets only the conversation's agent propose, validates, keeps one pending, and creates nothing", async () => {
|
||||
const seeded = await seed();
|
||||
const started = await start(seeded, seeded.tasks.weekly.id, { agentId: seeded.agents.analyst.id });
|
||||
const issueId = started.body.conversation.issueId as string;
|
||||
expect((await propose(seeded, seeded.agents.watcher.id, issueId, SCHEDULE)).status).toBe(403);
|
||||
expect((await propose(seeded, seeded.agents.watcher.id, issueId, SCHEDULE)).status).toBe(404);
|
||||
expect((await request(seeded.app).post(`/api/issues/${issueId}/automation-proposals`).send(SCHEDULE)).status).toBe(403);
|
||||
expect((await propose(seeded, seeded.agents.analyst.id, seeded.tasks.weekly.id, SCHEDULE)).status).toBe(422);
|
||||
expect((await propose(seeded, seeded.agents.analyst.id, issueId, { ...SCHEDULE, trigger: { kind: "schedule", cadence: { frequency: "weekly", time: "16:00" } } })).status).toBe(400);
|
||||
@@ -318,9 +318,8 @@ describeEmbeddedPostgres("automation conversations and standing checks", () => {
|
||||
const before = row(await read(seeded), seeded.responsibilities.finance.id);
|
||||
expect(before).toMatchObject({ level: "manual", automationCount: 0, manualTaskCount: 3 });
|
||||
const { issueId, interactionId } = await proposed(seeded, seeded.tasks.weekly.id, seeded.agents.analyst.id, SCHEDULE);
|
||||
// A person without the assignment permission cannot accept.
|
||||
expect((await request(createApp(sessionBoardActor(seeded.company.id, OTHER)))
|
||||
.post(`/api/issues/${issueId}/automation-proposals/${interactionId}/accept`).send({ timezone: "UTC" })).status).toBe(403);
|
||||
.post(`/api/issues/${issueId}/automation-proposals/${interactionId}/accept`).send({ timezone: "UTC" })).status).toBe(404);
|
||||
|
||||
const accepts = await Promise.all([1, 2].map(() =>
|
||||
request(seeded.app).post(`/api/issues/${issueId}/automation-proposals/${interactionId}/accept`).send({ timezone: "America/New_York" })));
|
||||
|
||||
@@ -284,14 +284,14 @@ describeEmbeddedPostgres("responsibility automation read", () => {
|
||||
const seeded = await seed();
|
||||
// Agents name the person.
|
||||
const agent: Actor = { type: "agent", companyId: seeded.company.id, agentId: seeded.agent.id, source: "agent_jwt" };
|
||||
expect((await read(seeded.company.id, agent)).status).toBe(422);
|
||||
expect((await read(seeded.company.id, agent)).status).toBe(403);
|
||||
const asAgent = await read(seeded.company.id, agent, `?ownerUserId=${OWNER}`);
|
||||
expect(asAgent.status).toBe(200);
|
||||
expect(asAgent.body.responsibilities).toHaveLength(4);
|
||||
expect(asAgent.status).toBe(403);
|
||||
expect(asAgent.body.responsibilities).toBeUndefined();
|
||||
|
||||
// Another person's dashboard by ownerUserId.
|
||||
const theirs = await read(seeded.company.id, boardActor(), "?ownerUserId=someone-else");
|
||||
expect(theirs.body.responsibilities.map((item: ResponsibilityAutomation) => item.responsibilityId)).toEqual([seeded.responsibilities.someoneElse.id]);
|
||||
expect(theirs.status).toBe(404);
|
||||
|
||||
// A board user from outside the company cannot read it.
|
||||
const outsider: Actor = {
|
||||
|
||||
@@ -292,7 +292,7 @@ describeEmbeddedPostgres("responsibility bar templates and bar conversations", (
|
||||
it("lets only the agent in the conversation propose, validates the bar, and writes nothing to the responsibility", async () => {
|
||||
const seeded = await seed();
|
||||
const issueId = (await startConversation(seeded)).body.conversation.issueId as string;
|
||||
expect((await propose(seeded.company.id, seeded.analyst.id, issueId)).status).toBe(403);
|
||||
expect((await propose(seeded.company.id, seeded.analyst.id, issueId)).status).toBe(404);
|
||||
expect((await request(seeded.app).post(`/api/issues/${issueId}/bar-proposals`).send(RANGE_PROPOSAL)).status).toBe(403);
|
||||
// An agent from another company cannot reach it.
|
||||
const elsewhere = await seed();
|
||||
@@ -356,11 +356,11 @@ describeEmbeddedPostgres("responsibility bar templates and bar conversations", (
|
||||
const accept = (actor: Actor) => request(createApp(actor)).post(`/api/issues/${issueId}/bar-proposals/${offered.body.id}/accept`).send({});
|
||||
|
||||
expect((await accept(agentActor(seeded.company.id, seeded.ceo.id))).status).toBe(403);
|
||||
expect((await accept(sessionBoardActor(seeded.company.id, OTHER))).status).toBe(403);
|
||||
// An admin who does not own it may.
|
||||
const res = await accept(sessionBoardActor(seeded.company.id, OTHER, "admin"));
|
||||
expect((await accept(sessionBoardActor(seeded.company.id, OTHER))).status).toBe(404);
|
||||
await accept(sessionBoardActor(seeded.company.id, OTHER, "admin")).expect(404);
|
||||
const res = await accept(localBoardActor());
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.interaction).toMatchObject({ status: "accepted", resolvedByUserId: OTHER, result: { outcome: "accepted", responsibilityId: seeded.responsibility.id } });
|
||||
expect(res.body.interaction).toMatchObject({ status: "accepted", resolvedByUserId: OWNER, result: { outcome: "accepted", responsibilityId: seeded.responsibility.id } });
|
||||
expect(res.body.responsibility).toMatchObject({
|
||||
id: seeded.responsibility.id,
|
||||
standard: RANGE_PROPOSAL.standard,
|
||||
@@ -404,7 +404,7 @@ describeEmbeddedPostgres("responsibility bar templates and bar conversations", (
|
||||
const issueId = (await startConversation(seeded)).body.conversation.issueId as string;
|
||||
const offered = await propose(seeded.company.id, seeded.ceo.id, issueId);
|
||||
expect((await request(createApp(sessionBoardActor(seeded.company.id, OTHER)))
|
||||
.post(`/api/issues/${issueId}/bar-proposals/${offered.body.id}/decline`).send({})).status).toBe(403);
|
||||
.post(`/api/issues/${issueId}/bar-proposals/${offered.body.id}/decline`).send({})).status).toBe(404);
|
||||
const declined = await request(seeded.app).post(`/api/issues/${issueId}/bar-proposals/${offered.body.id}/decline`).send({});
|
||||
expect(declined.status).toBe(200);
|
||||
expect(declined.body).toMatchObject({ status: "rejected", result: { outcome: "declined" } });
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { resolveExternalTestDatabaseUrl } from "./helpers/external-test-database.js";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import express from "express";
|
||||
import request from "supertest";
|
||||
@@ -88,6 +89,54 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
await instanceSettingsService(db).updateExperimental({ enableResponsibilities: true });
|
||||
});
|
||||
|
||||
it("splits a previously shared area, preserves each owner's history and hides unattributed areas", async () => {
|
||||
const migration = readFileSync(new URL("../../../packages/db/src/migrations/0500_funny_malcolm_colcord.sql", import.meta.url), "utf8");
|
||||
await db.$client.begin(async (tx) => {
|
||||
await tx`set local search_path to pg_temp`;
|
||||
await tx.unsafe(`create temp table responsibility_areas (
|
||||
id uuid primary key, company_id uuid, title text, description text, status text default 'active',
|
||||
source text, proposed_by_agent_id uuid, sort_order integer, created_at timestamptz, updated_at timestamptz
|
||||
) on commit drop`);
|
||||
await tx`create unique index responsibility_areas_company_title_uq on responsibility_areas(company_id, lower(title))`;
|
||||
await tx`create temp table responsibilities (id uuid, company_id uuid, owner_user_id text, area_id uuid) on commit drop`;
|
||||
await tx`create temp table activity_log (company_id uuid, actor_type text, actor_id text, action text, entity_type text, entity_id text, details jsonb) on commit drop`;
|
||||
await tx`create temp table responsibility_dashboard_versions (company_id uuid, owner_user_id text, snapshot jsonb, snapshot_hash text) on commit drop`;
|
||||
await tx`create temp table issues (id uuid, company_id uuid, visibility text, privacy_root_issue_id uuid, responsible_user_id text, origin_id text, created_by_user_id text, origin_kind text) on commit drop`;
|
||||
await tx`create temp table issue_thread_interactions (company_id uuid, kind text, status text, payload jsonb) on commit drop`;
|
||||
const company = randomUUID();
|
||||
const shared = randomUUID();
|
||||
const empty = randomUUID();
|
||||
const unknown = randomUUID();
|
||||
await tx`insert into responsibility_areas (id, company_id, title) values
|
||||
(${shared}, ${company}, 'Operations'), (${empty}, ${company}, 'Future work'), (${unknown}, ${company}, 'Unattributed')`;
|
||||
await tx`insert into responsibilities values (gen_random_uuid(), ${company}, 'Alex', ${shared}), (gen_random_uuid(), ${company}, 'Blair', ${shared})`;
|
||||
await tx`insert into activity_log values (${company}, 'user', 'Alex', 'responsibility_area.created', 'responsibility_area', ${empty}, null)`;
|
||||
await tx`insert into responsibility_dashboard_versions values (${company}, 'Blair', ${JSON.stringify({
|
||||
areas: [{ id: shared, title: "Operations" }], responsibilities: [{ areaId: shared }], createdAreaIds: [shared],
|
||||
})}::jsonb, 'old')`;
|
||||
await tx`insert into issue_thread_interactions values (${company}, 'propose_dashboard_changes', 'pending', ${JSON.stringify({
|
||||
ownerUserId: "Blair", changes: [{ groupAreaId: shared, fromAreaId: shared }],
|
||||
})}::jsonb)`;
|
||||
// The old overview included every active area, even for a newcomer.
|
||||
expect(await tx`select id from responsibility_areas where company_id = ${company} and status = 'active'`).toHaveLength(3);
|
||||
for (const statement of migration.split("--> statement-breakpoint")) await tx.unsafe(statement);
|
||||
const rows = await tx`select r.owner_user_id as owner, a.id from responsibilities r
|
||||
join responsibility_areas a on a.id = r.area_id and r.owner_user_id = a.owner_user_id order by owner`;
|
||||
expect(rows).toHaveLength(2);
|
||||
expect(rows[0]).toEqual({ owner: "Alex", id: shared });
|
||||
expect(rows[1].id).not.toBe(shared);
|
||||
const [proposal] = await tx`select payload from issue_thread_interactions`;
|
||||
expect(proposal.payload.changes).toEqual([{ groupAreaId: rows[1].id, fromAreaId: rows[1].id }]);
|
||||
const [version] = await tx`select snapshot from responsibility_dashboard_versions`;
|
||||
expect(version.snapshot).toMatchObject({
|
||||
areas: [{ id: rows[1].id, title: "Operations" }], responsibilities: [{ areaId: rows[1].id }], createdAreaIds: [rows[1].id],
|
||||
});
|
||||
expect(await tx`select id from responsibility_areas where owner_user_id = 'Alex' and id = ${empty}`).toHaveLength(1);
|
||||
expect(await tx`select id from responsibility_areas where owner_user_id is null`).toMatchObject([{ id: unknown }]);
|
||||
expect(await tx`select id from responsibility_areas where owner_user_id = 'New member'`).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
function createApp(actor: Actor) {
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
@@ -103,6 +152,23 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
return app;
|
||||
}
|
||||
|
||||
it("keeps two dashboards private when teammates create the same area", async () => {
|
||||
const { company, app } = await seed();
|
||||
const second = createApp(sessionBoardActor(company.id, OTHER, "owner"));
|
||||
const path = `/api/companies/${company.id}/responsibility-areas`;
|
||||
const overview = `/api/companies/${company.id}/responsibilities`;
|
||||
await db.insert(responsibilityAreas).values(Array.from({ length: 22 }, (_, i) => ({
|
||||
companyId: company.id, ownerUserId: OWNER, title: `Area ${i}`,
|
||||
})));
|
||||
expect((await request(second).get(overview).expect(200)).body.areas).toEqual([]);
|
||||
const mine = (await request(second).post(path).send({ title: "Area 0" }).expect(201)).body;
|
||||
const item = (await request(second).post(overview).send({ title: "Track operations", areaId: mine.id }).expect(201)).body;
|
||||
expect((await request(second).get(overview)).body.areas.map((area: { id: string }) => area.id)).toEqual([mine.id]);
|
||||
await request(app).get(`/api/responsibilities/${item.id}`).expect(404);
|
||||
await request(app).patch(`/api/responsibility-areas/${mine.id}`).send({ title: "Renamed" }).expect(404);
|
||||
expect((await request(app).get(overview)).body.areas).toHaveLength(22);
|
||||
});
|
||||
|
||||
async function seed(opts: { populated?: boolean } = {}) {
|
||||
const company = await db.insert(companies)
|
||||
.values({ name: "Dash Co", issuePrefix: `D${randomUUID().replace(/[^A-Z0-9]/gi, "").slice(0, 6).toUpperCase()}` })
|
||||
@@ -226,9 +292,9 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
const seeded = await seed({ populated: true });
|
||||
const url = `/api/companies/${seeded.company.id}/responsibility-dashboard`;
|
||||
const agentApp = createApp(agentActor(seeded.company.id, seeded.analyst.id));
|
||||
expect((await request(agentApp).get(url)).status).toBe(422);
|
||||
expect((await request(agentApp).get(`${url}?ownerUserId=${OWNER}`)).status).toBe(200);
|
||||
expect((await request(agentApp).get(`${url}/versions?ownerUserId=${OWNER}`)).status).toBe(200);
|
||||
expect((await request(agentApp).get(url)).status).toBe(403);
|
||||
expect((await request(agentApp).get(`${url}?ownerUserId=${OWNER}`)).status).toBe(403);
|
||||
expect((await request(agentApp).get(`${url}/versions?ownerUserId=${OWNER}`)).status).toBe(403);
|
||||
expect((await request(createApp(agentActor(randomUUID(), seeded.analyst.id))).get(`${url}?ownerUserId=${OWNER}`)).status).toBe(403);
|
||||
// An agent's read never saves a version.
|
||||
expect(await versionsOf(seeded)).toHaveLength(0);
|
||||
@@ -313,14 +379,13 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
expect(second.body.conversation.issueId).not.toBe(issueId);
|
||||
});
|
||||
|
||||
it("lets only the person or an admin start it, and says so when no agent can hold it", async () => {
|
||||
it("lets only the dashboard owner start it, and says so when no agent can hold it", async () => {
|
||||
const seeded = await seed();
|
||||
expect((await start(seeded, { mode: "create", ownerUserId: OWNER }, createApp(sessionBoardActor(seeded.company.id, OTHER)))).status).toBe(403);
|
||||
expect((await start(seeded, { mode: "create", ownerUserId: OWNER }, createApp(sessionBoardActor(seeded.company.id, OTHER)))).status).toBe(404);
|
||||
expect((await start(seeded, { mode: "create" }, createApp(agentActor(seeded.company.id, seeded.ceo.id)))).status).toBe(403);
|
||||
// An admin may start one for someone else; their own dashboard is untouched.
|
||||
// Company administration grants no access to personal dashboards.
|
||||
const forOther = await start(seeded, { mode: "create", ownerUserId: OTHER });
|
||||
expect(forOther.status).toBe(201);
|
||||
expect(forOther.body.ownerUserId).toBe(OTHER);
|
||||
expect(forOther.status).toBe(404);
|
||||
expect((await start(seeded, { mode: "create", ownerUserId: "stranger" })).status).toBe(404);
|
||||
|
||||
const quiet = await seed();
|
||||
@@ -371,7 +436,7 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
it("lets only the conversation's agent propose, and writes nothing", async () => {
|
||||
const seeded = await seed();
|
||||
const issueId = (await start(seeded)).body.conversation.issueId as string;
|
||||
expect((await propose(seeded, issueId, FIRST_DASHBOARD, seeded.analyst.id)).status).toBe(403);
|
||||
expect((await propose(seeded, issueId, FIRST_DASHBOARD, seeded.analyst.id)).status).toBe(404);
|
||||
expect((await request(seeded.app).post(`/api/issues/${issueId}/dashboard-changes`).send(FIRST_DASHBOARD)).status).toBe(403);
|
||||
const elsewhere = await seed();
|
||||
expect((await request(createApp(agentActor(elsewhere.company.id, elsewhere.ceo.id))).post(`/api/issues/${issueId}/dashboard-changes`).send(FIRST_DASHBOARD)).status).toBe(404);
|
||||
@@ -402,8 +467,9 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
it("validates each kind of change against the dashboard", async () => {
|
||||
const seeded = await seed({ populated: true });
|
||||
const issueId = (await start(seeded, { mode: "edit" })).body.conversation.issueId as string;
|
||||
const [archived] = await db.insert(responsibilityAreas).values({ companyId: seeded.company.id, title: "Old area", status: "archived" }).returning();
|
||||
const [theirs] = await db.insert(responsibilities).values({ companyId: seeded.company.id, ownerUserId: OTHER, title: "Theirs", status: "active", areaId: seeded.areas.Hiring }).returning();
|
||||
const [archived] = await db.insert(responsibilityAreas).values({ companyId: seeded.company.id, ownerUserId: OWNER, title: "Old area", status: "archived" }).returning();
|
||||
const [otherArea] = await db.insert(responsibilityAreas).values({ companyId: seeded.company.id, ownerUserId: OTHER, title: "Hiring" }).returning();
|
||||
const [theirs] = await db.insert(responsibilities).values({ companyId: seeded.company.id, ownerUserId: OTHER, title: "Theirs", status: "active", areaId: otherArea!.id }).returning();
|
||||
const fails = async (changes: object[], status: number, words?: string) => {
|
||||
const res = await propose(seeded, issueId, { changes });
|
||||
expect(res.status, JSON.stringify(changes)).toBe(status);
|
||||
@@ -427,7 +493,7 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
await fails([{ op: "add_area", ref: "f", name: "fundraising" }], 422, "already exists");
|
||||
await fails([{ op: "rename_area", areaId: fund, name: "Hiring" }], 422, "already called");
|
||||
await fails([{ op: "rename_area", areaId: fund, name: "Fundraising" }], 422, "already has that name");
|
||||
await fails([{ op: "remove_area", areaId: hiring, reason: "Not yours" }], 422, "another person");
|
||||
await fails([{ op: "remove_area", areaId: otherArea!.id, reason: "Not yours" }], 422, "No area");
|
||||
await fails([{ op: "reword_responsibility", responsibilityId: theirs!.id, sentence: "Mine now." }], 422, "not one of this person's");
|
||||
await fails([{ op: "reword_responsibility", responsibilityId: deck, sentence: "The deck is always current." }], 422, "same as the one it has");
|
||||
await fails([{ op: "move_responsibility", responsibilityId: deck, areaId: fund }], 422, "already in that area");
|
||||
@@ -435,7 +501,7 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
// A rename of a shared area says who else sees it.
|
||||
const shared = await propose(seeded, issueId, { changes: [{ op: "rename_area", areaId: hiring, name: "Recruiting" }] });
|
||||
expect(shared.status).toBe(201);
|
||||
expect(shared.body.payload.changes[0]).toMatchObject({ fromName: "Hiring", name: "Recruiting", sharedWith: 1 });
|
||||
expect(shared.body.payload.changes[0]).toMatchObject({ fromName: "Hiring", name: "Recruiting", sharedWith: 0 });
|
||||
// A removed area lists what goes with it, minus what is moved out.
|
||||
const removal = await propose(seeded, issueId, {
|
||||
changes: [
|
||||
@@ -477,7 +543,7 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
expect(logged).toEqual(expect.arrayContaining(["responsibility_dashboard.changes_applied", "issue.thread_interaction_accepted"]));
|
||||
// Only the person or an admin applies.
|
||||
const next = await propose(seeded, issueId, { changes: [{ op: "add_area", ref: "x", name: "Ops" }] });
|
||||
expect((await accept(seeded, issueId, next.body.id, {}, createApp(sessionBoardActor(seeded.company.id, OTHER)))).status).toBe(403);
|
||||
expect((await accept(seeded, issueId, next.body.id, {}, createApp(sessionBoardActor(seeded.company.id, OTHER)))).status).toBe(404);
|
||||
expect((await accept(seeded, issueId, next.body.id, {}, createApp(agentActor(seeded.company.id, seeded.ceo.id)))).status).toBe(403);
|
||||
});
|
||||
|
||||
@@ -538,12 +604,12 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
{ op: "remove_area", areaId: seeded.areas.Fundraising, reason: "The raise is done." },
|
||||
],
|
||||
});
|
||||
// Someone else files a responsibility in Fundraising meanwhile.
|
||||
await db.insert(responsibilities).values({ companyId: seeded.company.id, ownerUserId: OTHER, title: "Theirs", status: "active", areaId: seeded.areas.Fundraising });
|
||||
// The destination is archived after the proposal was made.
|
||||
await db.update(responsibilityAreas).set({ status: "archived" }).where(eq(responsibilityAreas.id, seeded.areas.Hiring));
|
||||
const before = await dashboard(seeded);
|
||||
const refused = await accept(seeded, issueId, proposed.body.id);
|
||||
expect(refused.status).toBe(409);
|
||||
expect(refused.body.error).toContain("Someone else now has responsibilities in \"Fundraising\"");
|
||||
expect(refused.body.error).toContain("removed since");
|
||||
expect(await dashboard(seeded)).toEqual(before);
|
||||
expect(await versionsOf(seeded)).toHaveLength(0);
|
||||
const [card] = await db.select().from(issueThreadInteractions).where(eq(issueThreadInteractions.id, proposed.body.id));
|
||||
@@ -679,9 +745,10 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
expect(areas.find((row) => row.id === seeded.areas.Hiring)).toMatchObject({ title: "Talent", status: "archived" });
|
||||
});
|
||||
|
||||
it("leaves a shared area's name and order alone, and never archives what someone else still uses", async () => {
|
||||
it("restores private area names and ordering without touching a teammate’s copy", async () => {
|
||||
const seeded = await seed({ populated: true });
|
||||
await db.insert(responsibilities).values({ companyId: seeded.company.id, ownerUserId: OTHER, title: "Theirs", status: "active", areaId: seeded.areas.Hiring });
|
||||
const [otherArea] = await db.insert(responsibilityAreas).values({ companyId: seeded.company.id, ownerUserId: OTHER, title: "Hiring" }).returning();
|
||||
await db.insert(responsibilities).values({ companyId: seeded.company.id, ownerUserId: OTHER, title: "Theirs", status: "active", areaId: otherArea!.id });
|
||||
const svc = responsibilityDashboardVersionService(db);
|
||||
const first = await db.transaction((tx) => svc.checkpoint(tx, seeded.company.id, OWNER, OWNER));
|
||||
await request(seeded.app).patch(`/api/responsibility-areas/${seeded.areas.Hiring}`).send({ title: "Recruiting", sortOrder: 5 });
|
||||
@@ -690,7 +757,7 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
await request(seeded.app).patch(`/api/responsibilities/${seeded.items.pipeline}`).send({ areaId: seeded.areas.Fundraising });
|
||||
await request(seeded.app).post(`/api/responsibility-dashboard-versions/${first.row.id}/restore`).send({});
|
||||
const areas = await areaRows(seeded);
|
||||
expect(areas.find((row) => row.id === seeded.areas.Hiring)).toMatchObject({ title: "Recruiting", sortOrder: 5, status: "active" });
|
||||
expect(areas.find((row) => row.id === seeded.areas.Hiring)).toMatchObject({ title: "Hiring", sortOrder: 0, status: "active" });
|
||||
expect(areas.find((row) => row.id === seeded.areas.Fundraising)).toMatchObject({ title: "Fundraising" });
|
||||
expect((await ownRows(seeded)).find((row) => row.id === seeded.items.pipeline)).toMatchObject({ areaId: seeded.areas.Hiring });
|
||||
|
||||
@@ -700,17 +767,18 @@ describeEmbeddedPostgres("dashboard conversations, change sets and versions", ()
|
||||
}));
|
||||
await request(seeded.app).post(`/api/responsibility-dashboard-versions/${blank.row.id}/restore`).send({});
|
||||
const after = await areaRows(seeded);
|
||||
expect(after.find((row) => row.id === seeded.areas.Hiring)).toMatchObject({ status: "active" });
|
||||
expect(after.find((row) => row.id === seeded.areas.Hiring)).toMatchObject({ status: "archived" });
|
||||
expect(after.find((row) => row.id === otherArea!.id)).toMatchObject({ title: "Hiring", status: "active" });
|
||||
expect(after.find((row) => row.id === seeded.areas.Fundraising)).toMatchObject({ status: "archived" });
|
||||
expect((await ownRows(seeded)).every((row) => row.status === "let_go")).toBe(true);
|
||||
expect(await db.select().from(responsibilities).where(eq(responsibilities.ownerUserId, OTHER)).then((rows) => rows.filter((row) => row.companyId === seeded.company.id).map((row) => row.status))).toEqual(["active"]);
|
||||
});
|
||||
|
||||
it("lets only the person or an admin restore", async () => {
|
||||
it("lets only the dashboard owner restore", async () => {
|
||||
const seeded = await seed();
|
||||
const { applied } = await createFirstDashboard(seeded);
|
||||
const url = `/api/responsibility-dashboard-versions/${applied.version.id}/restore`;
|
||||
expect((await request(createApp(sessionBoardActor(seeded.company.id, OTHER))).post(url).send({})).status).toBe(403);
|
||||
expect((await request(createApp(sessionBoardActor(seeded.company.id, OTHER))).post(url).send({})).status).toBe(404);
|
||||
expect((await request(createApp(agentActor(seeded.company.id, seeded.ceo.id))).post(url).send({})).status).toBe(403);
|
||||
expect((await request(createApp(sessionBoardActor(randomUUID(), OWNER))).post(url).send({})).status).toBe(404);
|
||||
expect((await request(seeded.app).post(`/api/responsibility-dashboard-versions/${randomUUID()}/restore`).send({})).status).toBe(404);
|
||||
|
||||
@@ -154,8 +154,8 @@ describeEmbeddedPostgres("responsibility metric sets", () => {
|
||||
describe("the read", () => {
|
||||
it("is 404 with the flag off, and follows the detail route's access", async () => {
|
||||
const seeded = await seed();
|
||||
expect((await read(createApp(sessionBoardActor(seeded.company.id, OTHER)), seeded.id)).status).toBe(200);
|
||||
expect((await read(createApp(agentActor(seeded.company.id, seeded.ceo.id)), seeded.id)).status).toBe(200);
|
||||
expect((await read(createApp(sessionBoardActor(seeded.company.id, OTHER)), seeded.id)).status).toBe(404);
|
||||
expect((await read(createApp(agentActor(seeded.company.id, seeded.ceo.id)), seeded.id)).status).toBe(403);
|
||||
// Another company's board user gets what the detail route gives them.
|
||||
const outsider = createApp(sessionBoardActor(randomUUID(), OTHER));
|
||||
const detail = await request(outsider).get(`/api/responsibilities/${seeded.id}`);
|
||||
@@ -230,7 +230,7 @@ describeEmbeddedPostgres("responsibility metric sets", () => {
|
||||
expect(row!.metricCurrent).toBe(11);
|
||||
expect((await record(analyst, seeded.id, "primary", { value: true })).status).toBe(422);
|
||||
// A teammate who does not own it may not record either.
|
||||
expect((await record(createApp(sessionBoardActor(seeded.company.id, OTHER)), seeded.id, "primary", { value: 3 })).status).toBe(403);
|
||||
expect((await record(createApp(sessionBoardActor(seeded.company.id, OTHER)), seeded.id, "primary", { value: 3 })).status).toBe(404);
|
||||
const logged = await db.select({ action: activityLog.action }).from(activityLog).where(eq(activityLog.companyId, seeded.company.id));
|
||||
expect(logged.map((entry) => entry.action)).toEqual(expect.arrayContaining(["responsibility.metric_reading_recorded", "responsibility.metric_updated"]));
|
||||
});
|
||||
@@ -300,7 +300,7 @@ describeEmbeddedPostgres("responsibility metric sets", () => {
|
||||
describe("chosen sets", () => {
|
||||
it("lets the owner set and remove supporting metrics; others may not", async () => {
|
||||
const seeded = await seed();
|
||||
expect((await request(createApp(sessionBoardActor(seeded.company.id, OTHER))).put(`/api/responsibilities/${seeded.id}/metrics`).send({ metrics: SUPPORTING })).status).toBe(403);
|
||||
expect((await request(createApp(sessionBoardActor(seeded.company.id, OTHER))).put(`/api/responsibilities/${seeded.id}/metrics`).send({ metrics: SUPPORTING })).status).toBe(404);
|
||||
expect((await request(createApp(agentActor(seeded.company.id, seeded.analyst.id))).put(`/api/responsibilities/${seeded.id}/metrics`).send({ metrics: SUPPORTING })).status).toBe(403);
|
||||
expect((await request(seeded.app).put(`/api/responsibilities/${seeded.id}/metrics`).send({ metrics: [...SUPPORTING, { ...SUPPORTING[1], title: "Third" }] })).status).toBe(400);
|
||||
const set = await request(seeded.app).put(`/api/responsibilities/${seeded.id}/metrics`).send({ metrics: SUPPORTING, primaryDisplay: "line" });
|
||||
@@ -348,7 +348,7 @@ describeEmbeddedPostgres("responsibility metric sets", () => {
|
||||
expect(primary.body).toMatchObject({ source: "chosen", chosenBy: { userId: OWNER } });
|
||||
expect((await showAs(seeded.app, seeded.id, "primary", "percent")).status).toBe(422);
|
||||
|
||||
expect((await showAs(createApp(sessionBoardActor(seeded.company.id, OTHER)), seeded.id, "primary", "line")).status).toBe(403);
|
||||
expect((await showAs(createApp(sessionBoardActor(seeded.company.id, OTHER)), seeded.id, "primary", "line")).status).toBe(404);
|
||||
expect((await showAs(createApp(agentActor(seeded.company.id, seeded.analyst.id)), seeded.id, "primary", "line")).status).toBe(403);
|
||||
expect((await showAs(seeded.app, seeded.id, randomUUID(), "line")).status).toBe(404);
|
||||
const logged = await db.select({ details: activityLog.details }).from(activityLog)
|
||||
|
||||
@@ -185,8 +185,8 @@ describeEmbeddedPostgres("a responsibility's recent runs", () => {
|
||||
const seeded = await seed();
|
||||
await run(seeded, seeded.issues.direct.id, 5);
|
||||
// A teammate and an agent in the company read it, as they read the detail.
|
||||
expect((await read(createApp(sessionBoardActor(seeded.company.id, OTHER)), seeded.id)).status).toBe(200);
|
||||
expect((await read(createApp(agentActor(seeded.company.id, seeded.ceo.id)), seeded.id)).status).toBe(200);
|
||||
expect((await read(createApp(sessionBoardActor(seeded.company.id, OTHER)), seeded.id)).status).toBe(404);
|
||||
expect((await read(createApp(agentActor(seeded.company.id, seeded.ceo.id)), seeded.id)).status).toBe(403);
|
||||
// Another company's board user gets what the detail route gives them.
|
||||
const outsider = createApp(sessionBoardActor(randomUUID(), OTHER));
|
||||
const detail = await request(outsider).get(`/api/responsibilities/${seeded.id}`);
|
||||
|
||||
@@ -192,8 +192,8 @@ describeEmbeddedPostgres("agent-written responsibility status", () => {
|
||||
expect(byOwner.status).toBe(201);
|
||||
expect(byOwner.body.current).toMatchObject({ status: "behind", agentId: null, userId: OWNER });
|
||||
|
||||
expect((await write(seeded, sessionBoardActor(seeded.company.id, OTHER))).status).toBe(403);
|
||||
expect((await write(seeded, sessionBoardActor(seeded.company.id, OTHER, "admin"))).status).toBe(201);
|
||||
expect((await write(seeded, sessionBoardActor(seeded.company.id, OTHER))).status).toBe(404);
|
||||
expect((await write(seeded, sessionBoardActor(seeded.company.id, OTHER, "admin"))).status).toBe(404);
|
||||
|
||||
// Nobody names the author: the body is strict, and the record follows the caller.
|
||||
const forged = await write(seeded, agentActor(seeded.company.id, seeded.builder.id), { ...REPORT, agentId: seeded.ceo.id });
|
||||
@@ -203,17 +203,17 @@ describeEmbeddedPostgres("agent-written responsibility status", () => {
|
||||
|
||||
const rows = await db.select().from(responsibilityStatusReports).where(eq(responsibilityStatusReports.responsibilityId, seeded.responsibility.id));
|
||||
expect(rows.map((row) => [row.agentId, row.userId]).sort()).toEqual([
|
||||
[null, OTHER], [null, OWNER], [seeded.analyst.id, null], [seeded.builder.id, null],
|
||||
[null, OWNER], [seeded.analyst.id, null], [seeded.builder.id, null],
|
||||
].sort());
|
||||
|
||||
const history = (await read(seeded)).body.history as Array<{ userId: string | null }>;
|
||||
expect(history).toHaveLength(4);
|
||||
expect(history[0]!.userId).toBe(OTHER);
|
||||
expect(history).toHaveLength(3);
|
||||
expect(history[0]!.userId).toBe(OWNER);
|
||||
|
||||
const logged = await db.select({ action: activityLog.action, details: activityLog.details }).from(activityLog)
|
||||
.where(and(eq(activityLog.companyId, seeded.company.id), eq(activityLog.action, "responsibility.status_reported")));
|
||||
expect(logged).toHaveLength(4);
|
||||
expect(logged.map((row) => (row.details as { writtenBy: string }).writtenBy).sort()).toEqual(["agent", "agent", "user", "user"]);
|
||||
expect(logged).toHaveLength(3);
|
||||
expect(logged.map((row) => (row.details as { writtenBy: string }).writtenBy).sort()).toEqual(["agent", "agent", "user"]);
|
||||
});
|
||||
|
||||
it("checks the message's shape", async () => {
|
||||
@@ -252,7 +252,7 @@ describeEmbeddedPostgres("agent-written responsibility status", () => {
|
||||
const ask = () => request(owner).post(`/api/responsibilities/${seeded.responsibility.id}/status-report/request`).send({});
|
||||
|
||||
// Someone who may not edit the responsibility cannot ask.
|
||||
expect((await request(createApp(sessionBoardActor(seeded.company.id, OTHER))).post(`/api/responsibilities/${seeded.responsibility.id}/status-report/request`).send({})).status).toBe(403);
|
||||
expect((await request(createApp(sessionBoardActor(seeded.company.id, OTHER))).post(`/api/responsibilities/${seeded.responsibility.id}/status-report/request`).send({})).status).toBe(404);
|
||||
expect((await request(createApp(agentActor(seeded.company.id, seeded.builder.id))).post(`/api/responsibilities/${seeded.responsibility.id}/status-report/request`).send({})).status).toBe(403);
|
||||
|
||||
const first = await ask();
|
||||
@@ -404,8 +404,8 @@ describeEmbeddedPostgres("agent-written responsibility status", () => {
|
||||
const seeded = await seed();
|
||||
const url = `/api/companies/${seeded.company.id}/responsibilities/status-reports`;
|
||||
const agentRead = await request(createApp(agentActor(seeded.company.id, seeded.builder.id))).get(url);
|
||||
expect(agentRead.status).toBe(422);
|
||||
expect((await request(createApp(agentActor(seeded.company.id, seeded.builder.id))).get(`${url}?ownerUserId=${OWNER}`)).status).toBe(200);
|
||||
expect(agentRead.status).toBe(403);
|
||||
expect((await request(createApp(agentActor(seeded.company.id, seeded.builder.id))).get(`${url}?ownerUserId=${OWNER}`)).status).toBe(403);
|
||||
expect((await request(createApp(agentActor(randomUUID(), seeded.builder.id))).get(url)).status).toBe(403);
|
||||
|
||||
await instanceSettingsService(db).updateExperimental({ enableResponsibilities: false });
|
||||
|
||||
@@ -200,9 +200,8 @@ describeEmbeddedPostgres("responsibility summary routes", () => {
|
||||
}).returning().then((rows) => rows[0]!);
|
||||
const agentApp = createApp(agentActor(company.id, agent.id)).app;
|
||||
const missingOwner = await request(agentApp).get(`/api/companies/${company.id}/responsibilities/summary`);
|
||||
expect(missingOwner.status).toBe(422);
|
||||
expect(missingOwner.body.error).toContain("ownerUserId is required");
|
||||
expect((await request(agentApp).get(`/api/companies/${company.id}/responsibilities/summary?ownerUserId=${OWNER}`)).status).toBe(200);
|
||||
expect((await request(agentApp).get(`/api/responsibilities/${created.body.id}/summary`)).status).toBe(200);
|
||||
expect(missingOwner.status).toBe(403);
|
||||
expect((await request(agentApp).get(`/api/companies/${company.id}/responsibilities/summary?ownerUserId=${OWNER}`)).status).toBe(403);
|
||||
expect((await request(agentApp).get(`/api/responsibilities/${created.body.id}/summary`)).status).toBe(403);
|
||||
});
|
||||
});
|
||||
@@ -117,6 +117,7 @@ describeEmbeddedPostgres("routine suggestions", () => {
|
||||
priority: "medium",
|
||||
assigneeAgentId: agent.id,
|
||||
originKind: input.originKind ?? "manual",
|
||||
responsibleUserId: OWNER,
|
||||
parentId: input.parentId ?? null,
|
||||
createdByUserId: OWNER,
|
||||
}).returning().then((rows) => rows[0]!);
|
||||
|
||||
Reference in new issue
Block a user