Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ fixtures after reviewing a writer change:
UPDATE_CONSOLE_WIRE_FIXTURES=1 go test ./cmd/server/internal/api -run '^TestConsoleWriterContract$'
```

The existing served `openapi.json` remains byte-identical to the public
`appserver-go v0.5.0` Console contract. Compatibility tests check its listApps /
getApp fields and fixtures against the internal schema. Replacing that public
document needs separate review. This intentionally deviates from the design's
The served `openapi.json` is the committed public Console contract. It is
maintained separately and may add Console features while preserving every SDK
field from `appserver-go`. A server test checks served bytes against the committed
file; compatibility tests check its listApps / getApp fields and fixtures against
both the SDK and internal schema.
This intentionally deviates from the design's
single generated public document and separate `B/api-schema` package: the schema
currently has one TypeScript consumer, so it shares the SPA's Zod installation.
A package boundary is deferred until a second consumer needs it, avoiding
Expand All @@ -154,6 +156,11 @@ feature/model imports of the canonical schema directory, including type-only
imports, barrels, and assertions. PostgreSQL handler contract tests use the same
opt-in DSN and isolated-schema cleanup as the other server integration tests.

The role-based views contract adds `me.view`, app `permissions` and `contribution`,
the maintainer inbox, and comment-seen writes. Regenerate the internal artifact
with the command above after canonical schema changes. Comment-seen writes use
fetch keepalive so opening another page does not cancel the read receipt.

### NEW-APP conversation contracts (APT-753 / S4)

The same canonical schema directory now owns `build-sessions.ts` and
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const storeOpenTimeout = 30 * time.Second
// Tests shorten it.
var storeRetryInitial = time.Second

// The database-backed API can appear after HTTP startup. Reviewer enrichment
// The database-backed API can appear after HTTP startup. Console authority
// follows that same readiness transition instead of bypassing the pending handler.
type consoleAPI struct {
*pending.Handler
Expand Down Expand Up @@ -103,6 +103,7 @@ func consoleHandler(upstreamURL, projectID string) (*consoleAPI, func(), error)
}
connected := api.New(database, auth, upstream, links, publicURL)
connected.ConfigureBuildSessions(conversations, installationID)
connected.ConfigureConsoleAuthority(conversationPlatform)
console.current.Store(connected)
console.Swap(connected)
return database, nil
Expand Down
35 changes: 5 additions & 30 deletions cmd/server/internal/api/access_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,38 +110,13 @@ func (a *API) pendingAccessRequests(s *request) (any, int, error) {
if s.r.URL.Query().Get("status") != "pending" {
return nil, 0, httpx.Invalid("status must be pending")
}
// EditApp includes group managers even for private apps they cannot view.
// Union owned apps with topmost managed subtrees instead of widening Visible.
scope := "mine"
if s.actor.IsConsoleAdmin {
scope = "all"
}
apps, err := s.tx.Apps(s.actor, scope, "", "")
apps, err := s.tx.MaintainedApps(s.actor)
if err != nil {
return nil, 0, err
}
ids := make([]string, 0, len(apps))
seen := make(map[string]bool, len(apps))
add := func(apps []domain.App) {
for _, app := range apps {
if !seen[app.ID] && s.actor.EditApp(app) {
seen[app.ID] = true
ids = append(ids, app.ID)
}
}
}
add(apps)
if !s.actor.IsConsoleAdmin {
for _, group := range s.groups {
if !s.actor.ManageGroup(group.ID) || (group.ParentID != nil && s.actor.ManageGroup(*group.ParentID)) {
continue
}
apps, err := s.tx.AppsInSubtree(group.Path)
if err != nil {
return nil, 0, err
}
add(apps)
}
ids := make([]string, len(apps))
for i := range apps {
ids[i] = apps[i].ID
}
requests, err := s.tx.PendingAccessRequests(ids)
return requests, http.StatusOK, err
Expand Down Expand Up @@ -215,7 +190,7 @@ func (a *API) approveAccessRequest(s *request) (any, int, error) {
return struct {
Request domain.AppAccessRequest `json:"request"`
App domain.App `json:"app"`
}{r, updated}, http.StatusOK, err
}{r, s.appForCaller(updated)}, http.StatusOK, err
}

func (a *API) declineAccessRequest(s *request) (any, int, error) {
Expand Down
5 changes: 5 additions & 0 deletions cmd/server/internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type API struct {
stackURLs map[string]cachedStackURLs
builds *buildsession.Service
installationID string
authorityStacks consoleStackReader
}

type request struct {
Expand All @@ -52,6 +53,8 @@ type request struct {
bearer string
platformUnavailable bool
claims identity.Identity
authorityApps map[authorityRoute][]domain.App
authorityStackCache map[string]buildsession.ConsoleStack
}

type endpoint func(*request) (any, int, error)
Expand All @@ -68,6 +71,7 @@ func New(database *store.Store, auth *identity.Authenticator, upstream *platform
a.mux.Handle("GET /launcher/entries", launcher.NewEntriesHandler(appEntrySource{api: a}, a.identity.Authenticate))
a.mux.HandleFunc("GET /api/console/openapi.json", a.openAPI)
a.route("GET /api/console/me", false, true, a.me)
a.route("GET /api/console/inbox", false, true, a.inbox)
a.route("GET /api/console/resolve", false, true, a.resolve)
a.mux.Handle("/api/console/directory/", a.directoryProxy())
a.route("POST /api/console/admin/directory-migrate", true, true, a.migrateDirectory)
Expand All @@ -83,6 +87,7 @@ func New(database *store.Store, auth *identity.Authenticator, upstream *platform
a.route("DELETE /api/console/apps/{id}", true, true, a.deleteApp)
a.route("GET /api/console/apps/{id}/comments", false, true, a.comments)
a.route("POST /api/console/apps/{id}/comments", true, true, a.createComment)
a.route("POST /api/console/apps/{id}/comments/seen", true, true, a.markCommentsSeen)
a.route("DELETE /api/console/apps/{id}/comments/{cid}", true, true, a.deleteComment)
a.route("GET /api/console/apps/{id}/screenshots/{sid}", false, true, a.screenshot)
a.route("POST /api/console/apps/{id}/screenshots", true, true, a.uploadScreenshot)
Expand Down
35 changes: 27 additions & 8 deletions cmd/server/internal/api/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,27 @@ func (a *API) apps(s *request) (any, int, error) {
}
entries := make([]domain.DirectoryEntry, len(apps))
for i, app := range apps {
entries[i] = domain.EntryOf(app, s.actor.Visible(app))
app = s.appForCaller(app)
entries[i] = domain.EntryOf(app, app.Permissions.Use)
}
return appList[domain.DirectoryEntry]{Items: entries}, 200, nil
}
apps, err := s.tx.Apps(s.actor, scope, groupPath, query.Get("q"))
for i := range apps {
apps[i] = s.appForCaller(apps[i])
}
return appList[domain.App]{Items: apps}, 200, err
}

type appList[T any] struct {
Items []T `json:"items"`
}

func (s *request) appForCaller(app domain.App) domain.App {
app.Permissions = domain.Capabilities(s.actor, app)
return app
}

func (a *API) app(s *request) (any, int, error) {
app, err := s.tx.App(s.r.PathValue("id"))
if err != nil {
Expand All @@ -56,7 +65,7 @@ func (a *API) app(s *request) (any, int, error) {
if !s.actor.Visible(app) {
return nil, 0, httpx.NotFound()
}
return app, 200, nil
return s.appForCaller(app), 200, nil
}

func (s *request) boundApp() (domain.App, error) {
Expand All @@ -75,7 +84,8 @@ func (a *API) directoryEntry(s *request) (any, int, error) {
if err != nil {
return nil, 0, err
}
return domain.EntryOf(app, s.actor.Visible(app)), 200, nil
app = s.appForCaller(app)
return domain.EntryOf(app, app.Permissions.Use), 200, nil
}

func (a *API) appByPath(s *request) (any, int, error) {
Expand All @@ -90,7 +100,7 @@ func (a *API) appByPath(s *request) (any, int, error) {
if !s.actor.Visible(app) {
return nil, 0, httpx.NotFound()
}
return app, 200, nil
return s.appForCaller(app), 200, nil
}

type appInput struct {
Expand All @@ -103,6 +113,7 @@ type appInput struct {
GroupID *string `json:"groupId"`
Slug *string `json:"slug"`
Share *domain.SharePolicy `json:"share"`
Contribution *domain.ContributionPolicy `json:"contribution"`
OwnerIDs *[]string `json:"ownerIds"`
}

Expand Down Expand Up @@ -152,6 +163,14 @@ func (s *request) applyApp(input appInput, app *domain.App, creating bool) error
if input.Share != nil {
app.Share = *input.Share
}
if input.Contribution != nil {
switch input.Contribution.Scope {
case "off", "group", "company":
app.Contribution = *input.Contribution
default:
return httpx.Invalid("contribution.scope must be off, group, or company")
}
}
if app.Tags == nil {
app.Tags = []string{}
}
Expand Down Expand Up @@ -211,7 +230,7 @@ func (a *API) createApp(s *request) (any, int, error) {
if input.OwnerIDs != nil {
return nil, 0, httpx.Invalid("ownerIds can only be changed after creation")
}
app := domain.App{ID: uuid.NewString(), CreatedBy: s.person, Share: domain.SharePolicy{Scope: "group"}}
app := domain.App{ID: uuid.NewString(), CreatedBy: s.person, Share: domain.SharePolicy{Scope: "group"}, Contribution: domain.ContributionPolicy{Scope: "group"}}
if input.GroupID != nil {
app.Share.GroupIDs = []string{*input.GroupID}
}
Expand Down Expand Up @@ -246,7 +265,7 @@ func (a *API) createApp(s *request) (any, int, error) {
return nil, 0, err
}
created, err := s.tx.App(app.ID)
return created, 201, err
return s.appForCaller(created), 201, err
}

func (s *request) editableApp() (domain.App, error) {
Expand Down Expand Up @@ -313,7 +332,7 @@ func (a *API) patchApp(s *request) (any, int, error) {
return nil, 0, err
}
updated, err = s.tx.App(app.ID)
return updated, 200, err
return s.appForCaller(updated), 200, err
}

func (a *API) bindApp(s *request) (any, int, error) {
Expand Down Expand Up @@ -341,7 +360,7 @@ func (a *API) bindApp(s *request) (any, int, error) {
return nil, 0, err
}
app, err = s.tx.App(app.ID)
return app, 200, err
return s.appForCaller(app), 200, err
}

func (a *API) deleteApp(s *request) (any, int, error) {
Expand Down
Loading