feat(api): GET /v1/projects — list the projects a caller can reach - #21
Open
marcorivm wants to merge 1 commit into
Open
feat(api): GET /v1/projects — list the projects a caller can reach#21marcorivm wants to merge 1 commit into
marcorivm wants to merge 1 commit into
Conversation
The OSS build serves no project-list endpoint: ossProjectRoutes defines only
/:projectId and /:projectId/access, and upstream serves the collection from
its closed cloud backend. That leaves no way to discover projects, which is
why user groups and project access have felt inert — the thing they grant
access to could not be enumerated.
listProjects mirrors canAccessProjectAsUser arm for arm, as a query rather
than a per-row check:
1. !CAPS.rbac -> the whole org (the gate no-ops there)
2. no role -> [] (suspended / non-member; the binding arm stays
INSIDE this gate so a stale binding never rescues)
3. admin or owner -> the whole org
4. otherwise -> projects carrying a binding for this user, direct
or through a group; role is not filtered, since
usage is role-blind
Drift between the two is a bug either way: listed-but-unreadable leaks a name
past its ProjectAccess bindings, readable-but-unlisted is a project you can
reach but never find. A test asserts the two agree for every seeded project.
The route deliberately carries no authorization of its own — there is no id to
resolve, so nothing to 404 and nothing to 403. listProjects IS the
authorization, and a member with no bindings correctly gets [] rather than a
403.
Matches upstream's client contract (Project[], optional X-Organization-Id),
so it also closes the v1.45.0 GetStartedPicker 404 recorded in
docs/upstream-sync/reviews/2026-08-05-v1.45.0.md.
Ordering is createdAt asc, id asc — the same as findUserDefaultProject, so the
project a caller lands on by default is the first one a switcher shows.
Slice 1 of docs/project-lifecycle.md.
marcorivm
force-pushed
the
feat/projects-list
branch
from
August 8, 2026 19:34
485a8de to
b7c3aa0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Slice 1 of #20. 3 files, ~150 lines — the smallest useful piece, and independently valuable.
What and why
ossProjectRoutesdefines only/:projectIdand/:projectId/access— there is no way to enumerate projects. Upstream serves the collection from its closed cloud backend, so the OSS build 404s it. That gap is why groups (#12) and project access (#13) feel inert: the thing they grant access to can't be discovered.This adds
GET /v1/projectsandlistProjects.The one thing worth reviewing carefully
listProjectsmust mirrorcanAccessProjectAsUserarm for arm — it is that per-row predicate expressed as a query. Drift either way is a real bug: listed-but-unreadable leaks a project name past itsProjectAccessbindings; readable-but-unlisted is a project you can reach but never find.canAccessProjectAsUserlistProjects!CAPS.rbacreturn truereturn false[]return truehasProjectBindingroleis deliberately not filtered in the binding arm — usage is role-blind, so a plainmemberbinding is a full use grant. A test asserts the two agree for every seeded project:The route carries no authorization of its own, on purpose. Unlike every other route in the file there is no id to resolve, so there is nothing to 404 and nothing to 403.
listProjectsis the authorization. A member of the org holding no bindings correctly gets[], not a 403 — asserted explicitly.Upstream
Matches upstream's client contract (
Project[], optionalX-Organization-Idoverride), so this also closes the v1.45.0GetStartedPicker404 recorded indocs/upstream-sync/reviews/2026-08-05-v1.45.0.md.Ordering is
createdAt asc, id asc— the same asfindUserDefaultProject, so the project you land on by default is the first one a switcher will show.Tests
12 new cases in
projects.test.ts(76 passing in the file, 1,156 across@onecli/api). Cross-org isolation, the group-binding arm viaMEMBER2, the zero-binding project (proj-4) staying invisible to a plain member, response shape leaking neithercreatedByUserIdnororganizationId, and 401/403 on the guard stack.One finding while writing them. I expected a suspended member to get
200 []; they get 401. Session auth resolves the default project throughactiveMembershipWhere, which a suspended member fails, so neither project nor org resolves and the request is rejected a layer earlier.listProjects's ownif (!role) return []arm is therefore defence-in-depth for direct service callers rather than a path this route can reach — kept anyway so the function mirrors the gate without depending on its caller having gated first. Both tests now assert the real behaviour, with the reasoning in a comment.Verification