Skip to content

feat(api): GET /v1/projects — list the projects a caller can reach - #21

Open
marcorivm wants to merge 1 commit into
docs/project-lifecyclefrom
feat/projects-list
Open

feat(api): GET /v1/projects — list the projects a caller can reach#21
marcorivm wants to merge 1 commit into
docs/project-lifecyclefrom
feat/projects-list

Conversation

@marcorivm

Copy link
Copy Markdown
Member

Slice 1 of #20. 3 files, ~150 lines — the smallest useful piece, and independently valuable.

What and why

ossProjectRoutes defines only /:projectId and /: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/projects and listProjects.

The one thing worth reviewing carefully

listProjects must mirror canAccessProjectAsUser arm 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 its ProjectAccess bindings; readable-but-unlisted is a project you can reach but never find.

canAccessProjectAsUser listProjects
!CAPS.rbac return true whole org
no role (suspended / non-member) return false []
admin or owner return true whole org
otherwise hasProjectBinding projects with a binding, direct or via group

role is deliberately not filtered in the binding arm — usage is role-blind, so a plain member binding is a full use grant. A test asserts the two agree for every seeded project:

it("agrees with GET /:projectId — everything listed is readable, and vice versa")

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. listProjects is the authorization. A member of the org holding no bindings correctly gets [], not a 403 — asserted explicitly.

Upstream

Matches upstream's client contract (Project[], optional X-Organization-Id override), so this 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 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 via MEMBER2, the zero-binding project (proj-4) staying invisible to a plain member, response shape leaking neither createdByUserId nor organizationId, 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 through activeMembershipWhere, which a suspended member fails, so neither project nor org resolves and the request is rejected a layer earlier. listProjects's own if (!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

pnpm --filter @onecli/api test    # 1156 passed, 0 failed
pnpm run check                    # lint + types + format clean

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
marcorivm force-pushed the feat/projects-list branch from 485a8de to b7c3aa0 Compare August 8, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant