Repository navigation
feat(search): filter by project and by the caller's project role - #454
Conversation
M0Rf30
left a comment
There was a problem hiding this comment.
The authorization side holds up: the filter only narrows the readable set, the cached map is copied rather than mutated, missing and foreign projects answer identically, admin-as-owner matches the projects API, and the system project grants nothing. Changes requested:
1. MCP search ignores the new qualifiers. internal/mcp/handlers.go:220 calls search.ParseQuery, which now consumes project: and project_role:, but the MCP tool never applies filter.Projects / filter.ProjectRoles. Before this PR lodash project:acme matched nothing; now it returns lodash from every readable repository, so the result looks scoped but isn't. Its query_too_broad message (search.TooBroadMessage) also suggests project:<project>, which MCP can't honour. Apply the same narrowing on the MCP path (preferred), or reject the qualifiers there and keep them out of its hints.
2. Docs still describe the old filter set.
- the
narrow_byschema description ininternal/api/openapi.json(and the generateddocs/reference/api/schemas.mdandweb/src/api/generated/types.gen.ts) still saysname:, format:, repo: in q, flagged=true; docs/integrations/api.md:203lists onlyq,format,repo: addprojectandproject_role;docs/getting-started/upgrading.md: an entry for the new parameters.
3. Cost (smaller). Every filtered request reads all repositories in all non-system projects, uncached, even for a caller with roles in two projects. Bound it with r.project_id = ANY(...) of the caller's projects for non-admins (and by name/slug when project= is set). ProjectRole(ctx, p, "") also loads ProjectRoles and discards it, then narrowToProjects loads it again; one Evaluate(..., "manage") plus one ProjectRoles is enough.
4. Tests (smaller). Missing cases: scoped token, deploy token, service account and legacy principal (the docs make claims about each); more than 50 project / project_role values -> 400; the cached readable map unchanged after a filtered request.
Nit: callers with no project role (anonymous, deploy tokens) still get the project:<project> hint on query_too_broad, though any project filter returns nothing for them.
Review of openartifact#454: - MCP: search_artifacts parsed project: and project_role: away but never applied them, so a filtered query searched every readable repository. The narrowing is now search.ProjectScope, shared by the HTTP handler and the MCP server (Server.SetProjectScope); without a scope a project-filtered MCP search finds nothing. - Cost: one Evaluate(manage) and one ProjectRoles per filtered request instead of ProjectRole plus ProjectRoles, and the repository query is bounded to the caller's projects (non-admins) and to the named projects (project=). - query_too_broad suggests project:<project> only to callers that hold a project role, on both paths. - Docs: narrow_by description (OpenAPI, generated schemas and web types), docs/integrations/api.md and an upgrade note. - Tests: scoped token, deploy token (also of an admin), service account and legacy principal; more than 50 project / project_role values is 400; the cached readable set is unchanged after a filtered request; MCP narrowing, the missing-scope case and its hint. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for the thorough review. All points addressed in the new commit:
Nit: One note: removing my explicit deploy-token exclusion doesn't change any result, because Checked locally: |
M0Rf30
left a comment
There was a problem hiding this comment.
Thanks, all four points verified. Two non-blocking nits for a follow-up if you like: on the too-broad path with a project filter, UsesProjects resolves the caller's roles a second time (reuse the result of NarrowToProjects); and the MCP path has no 50-value cap on project:/project_role: (the HTTP one does).
|
#453 is merged, so this now conflicts in |
GET /api/v1/search takes project (name or slug) and project_role (viewer, developer, maintainer, owner), both repeatable, and the project: and project_role: qualifiers in q. Both narrow the set of repositories the caller can already read, before the package and repository queries run, so they never add access and the repository hits honour them too. The role is the effective one the projects API reports as my_role (auth.Evaluator.ProjectRoles, owner everywhere for a global admin): project_role=viewer finds nothing for an admin, by design. A repository is kept only where the caller has a role in its project, so a project that does not exist and one without a role give the same empty answer, and repositories readable only through a permission target or anonymous access, or in the system project, never match. An unknown project_role is 400 invalid_filter, and query_too_broad now suggests project:<project>. Closes openartifact#445 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of openartifact#454: - MCP: search_artifacts parsed project: and project_role: away but never applied them, so a filtered query searched every readable repository. The narrowing is now search.ProjectScope, shared by the HTTP handler and the MCP server (Server.SetProjectScope); without a scope a project-filtered MCP search finds nothing. - Cost: one Evaluate(manage) and one ProjectRoles per filtered request instead of ProjectRole plus ProjectRoles, and the repository query is bounded to the caller's projects (non-admins) and to the named projects (project=). - query_too_broad suggests project:<project> only to callers that hold a project role, on both paths. - Docs: narrow_by description (OpenAPI, generated schemas and web types), docs/integrations/api.md and an upgrade note. - Tests: scoped token, deploy token (also of an admin), service account and legacy principal; more than 50 project / project_role values is 400; the cached readable set is unchanged after a filtered request; MCP narrowing, the missing-scope case and its hint. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Rebased onto main. The two entries now share one "Unreleased" section in Thanks for the two nits. I'll send them as a small follow-up: reuse the roles resolved for the narrowing on the too-broad path, and the 50-value cap for |
602d458 to
99024bd
Compare
M0Rf30
left a comment
There was a problem hiding this comment.
Thanks for the rebase. Code is fine, but the merge of docs/getting-started/upgrading.md went the wrong way: against main, this PR replaces #453's entries instead of adding to them (git diff origin/main pr/454 -- docs/getting-started/upgrading.md removes the oa props search NAME line and the Property search bullet). Please keep both, e.g.:
**What you must do**
- Check scripts that read the text output of `oa props search` line by line: the table now has a `NAME` column after `ARTIFACT_ID`. `--format json` still prints the list of ids.
- In a search query, a word starting with `project:` or `project_role:` is now a filter rather than search text.
- Nothing else is required.
**Changes.**
- **Property search.** …(as on main)
- **Search by project.** …(yours)I'll merge as soon as that's in and green.
M0Rf30
left a comment
There was a problem hiding this comment.
My mistake, sorry: I diffed a stale local ref of the pre-rebase commit. The rebased branch keeps both entries in one section, as you said. Merging.
) Follow-up to the review of #454: - ProjectScope.NarrowToProjects also returns whether the caller holds a project role. On a project-filtered search that is too broad, the HTTP handler and the MCP search tool reuse it for the project:<project> hint instead of resolving the caller's roles a second time. - search.CheckProjectFilters holds the project_role and 50-value rules. GET /api/v1/search answers them with 400 invalid_filter as before, and the MCP search tool now applies them too, as a tool error: an unknown project_role or more than 50 project: / project_role: values used to be accepted there (a typo silently matched nothing). - docs/integrations/mcp.md: the qualifiers search_artifacts takes. Co-authored-by: Areef <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Closes #445, with the names and rules agreed there.
GET /api/v1/searchgains two repeatable filters, usable as parameters or as qualifiers inq:projectproject:NAMEproject_roleproject_role:ROLEviewer,developer,maintainer,owner)project_role=vieweris the "Shared with me" preset;project_role=developer&project_role=maintainer&project_role=owneris "mine".Behaviour
narrowToProjectsininternal/search/project_filter.go) beforeSearchPageandSearchRepositoriesrun, so they can't add access, and the repository hits honour them too. The readable set may be cached and shared, so the narrowed one is a new map.my_role:auth.Evaluator.ProjectRoles(ownership, membership, group grants; nothing for anonymous, deploy and scoped tokens) plusownereverywhere for a global admin viaEvaluator.ProjectRole. For an admin,project_role=viewerreturns nothing, deliberately, and is tested.project_roleis400 invalid_filter(a typo shouldn't look like "no results"). Values per filter are capped at 50 likeformatandrepo.query_too_broadsuggestsproject:<project>when no project filter is used.checksumlookups ignore the project filters, as they already ignoreq,format,repo,groupandflagged; the parameter description says so.role:stays free text (tested), as you suggested.OpenAPI (parameters,
qdescription), the generated web client,docs/reference/api/search.mdandopenapi.json.gzare updated.Tests
internal/search/project_filter_integration_test.go(integration, Postgres, realauth.Evaluator). Callers: an owner of one project and viewer of another who also reads a third project's repository through a permission target and the system project through another; a user with only a permission target; a developer through a group grant; a global admin; anonymous. 18 cases cover parameters and qualifiers, "shared with me", "mine", both filters together, group grants, the system project, the admin rules, repository hits, and the identical answers for a missing and a foreign project. I checked that removing the "no role, no match" rule or the admin-as-owner rule makes them fail.Unit tests: the qualifiers and
role:inparser_test.go,400 invalid_filterfor unknown roles,project:<project>innarrow_by.Checked locally (macOS, Postgres 18):
make check,cmd/docgen -check,bun run typecheck, the unit suite with-race, the slim suite, andgo test -tags integration ./internal/search/.Not in this PR
project:in the palette's "too many matches" hint (shell.palette.tooBroad, in every locale). I'd send that as a follow-up to keep this one about the API. Or would you rather have it here?oa searchpassesqthrough, sooa search readme project:acmealready works. Dedicated--project/--project-roleflags could come with the UI follow-up.🤖 Generated with Claude Code