mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-15 18:56:05 +01:00
fix(search): apply task privacy to artifact results (#20595)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Private tasks are visible only to the people and agents that have access > - Company search already filters task results by the caller's task read condition > - Artifact results (agent documents, work products and attachments) in search, and the company artifacts list, did not use that condition > - So a company member could find a private task's document title and snippet through search > - This pull request applies the same task read condition to artifact results > - The benefit is that private task outputs stay private in search and in the artifacts list ## Linked Issues or Issue Description **What happened** An agent saved a document on a private task. A different company member without access to that task searched for a word in the document. The search returned the document as an artifact result with a snippet. **Expected behavior** Search and the artifacts list show artifacts only from tasks the caller can read. **Steps to reproduce** 1. Create a private task and let an agent save a document on it. 2. Sign in as a company member who cannot read the task. 3. Search for a word in the document, or open the company artifacts list. 4. See the private document in the results. ## What Changed - `company-search.ts`: artifact counts and artifact rows apply `options.issueReadCondition`. - `routes/companies.ts`: `GET /companies/:companyId/artifacts` passes the caller's `issueReadSqlCondition` to the artifacts service. ## Verification - Red then green: `cd server && npx vitest run src/__tests__/company-search-service.test.ts -t "private task artifacts"` (fails on `master` with the private document in the outsider's results). - Red then green: `npx vitest run src/__tests__/company-artifacts-service.test.ts -t "caller can read"`. - `npx vitest run src/__tests__/company-search-service.test.ts src/__tests__/company-search-extract-service.test.ts src/__tests__/company-search-extract-routes.test.ts src/__tests__/company-artifacts-service.test.ts` (all pass). - `tsc --noEmit -p server`: no errors in the changed files. ## Risks - Low risk. The read condition is the same one task results use. Callers with full access (local board, instance admin, privacy mode off) get `true` and see no change. ## Model Used - Anthropic Claude Opus 5.5 (`claude-opus-5-5`), tool use and code execution in Claude Code. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
491dfa1c6d
commit
accf22076f
5 files changed
+78
-7
No files matched your search
@@ -195,7 +195,7 @@ function pageByCursor<T extends { id: string; updatedAt: string }>(
|
||||
return { page, nextCursor };
|
||||
}
|
||||
|
||||
async function loadIssueGroupingRows(db: Db, companyId: string, seedIssueIds: Iterable<string>) {
|
||||
async function loadIssueGroupingRows(db: Db, companyId: string, seedIssueIds: Iterable<string>, readCondition?: SQL) {
|
||||
const rowsById = new Map<string, IssueGroupingRow>();
|
||||
let pending = [...new Set(seedIssueIds)];
|
||||
|
||||
@@ -209,7 +209,7 @@ async function loadIssueGroupingRows(db: Db, companyId: string, seedIssueIds: It
|
||||
updatedAt: issues.updatedAt,
|
||||
})
|
||||
.from(issues)
|
||||
.where(and(eq(issues.companyId, companyId), inArray(issues.id, pending)));
|
||||
.where(and(eq(issues.companyId, companyId), inArray(issues.id, pending), readCondition));
|
||||
|
||||
const nextPending = new Set<string>();
|
||||
for (const row of rows) {
|
||||
@@ -321,7 +321,8 @@ export function companyArtifactsService(db: Db, storage?: StorageService) {
|
||||
list: async (
|
||||
companyId: string,
|
||||
rawQuery: Partial<CompanyArtifactsQuery> = {},
|
||||
options: { issueConditions?: SQL[]; userId?: string } = {},
|
||||
/** `readCondition` limits artifacts and group tasks to tasks the caller can read. */
|
||||
options: { issueConditions?: SQL[]; readCondition?: SQL; userId?: string } = {},
|
||||
): Promise<CompanyArtifactsResponse> => {
|
||||
const query = companyArtifactsQuerySchema.parse(rawQuery);
|
||||
const cursor = decodeCursor(query.cursor);
|
||||
@@ -344,6 +345,7 @@ export function companyArtifactsService(db: Db, storage?: StorageService) {
|
||||
isNull(issues.hiddenAt),
|
||||
isNull(issues.harnessKind),
|
||||
...(options.issueConditions ?? []),
|
||||
...(options.readCondition ? [options.readCondition] : []),
|
||||
];
|
||||
const artifacts: CompanyArtifact[] = [];
|
||||
const artifactSortDates = new Map<string, string>();
|
||||
@@ -742,7 +744,7 @@ export function companyArtifactsService(db: Db, storage?: StorageService) {
|
||||
|
||||
const issueSeedIds = new Set(artifacts.map((artifact) => artifact.issue.id));
|
||||
if (query.groupIssueId) issueSeedIds.add(query.groupIssueId);
|
||||
const issueRows = await loadIssueGroupingRows(db, companyId, issueSeedIds);
|
||||
const issueRows = await loadIssueGroupingRows(db, companyId, issueSeedIds, options.readCondition);
|
||||
const groups = buildArtifactGroups({
|
||||
artifacts: sorted,
|
||||
companyPrefix: company.issuePrefix,
|
||||
|
||||
@@ -951,6 +951,7 @@ export function companySearchService(db: Db) {
|
||||
eq(issues.companyId, companyId),
|
||||
visibleIssueCondition(),
|
||||
...artifactIssueFilters,
|
||||
...(options?.issueReadCondition ? [options.issueReadCondition] : []),
|
||||
];
|
||||
const documentArtifactConditions = [
|
||||
eq(issueDocuments.companyId, companyId),
|
||||
@@ -1035,7 +1036,7 @@ export function companySearchService(db: Db) {
|
||||
const result = await companyArtifactsService(db).list(companyId, {
|
||||
q: normalizedQuery.slice(0, COMPANY_ARTIFACTS_MAX_QUERY_LENGTH),
|
||||
limit: Math.min(fetchLimit, COMPANY_ARTIFACTS_MAX_LIMIT),
|
||||
}, { issueConditions: issueFilters });
|
||||
}, { issueConditions: issueFilters, readCondition: options?.issueReadCondition });
|
||||
return result.artifacts;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user