feat: add organization scoping to chats (#23827)

Fixes https://github.com/coder/internal/issues/1436

* Adds organization_id to chats with backfill (workspace org → user org membership → default org)
* No support yet for ACLs (follow-up issue)
- Cross-org workspace binding rejected (both in `CreateChatRequest` and in `create_workspace` tool
- Adds `OrganizationAutocomplete` to `AgentCreateForm`
- Docs updated with `organization_id` in chats-api.md

> 🤖 Written by a Coder Agent. Reviewed by many humans and many agents.

---------

Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
This commit is contained in:
Cian Johnston
2026-04-13 12:31:25 +01:00
committed by GitHub
co-authored by Mathias Fredriksson
parent cb0b84a2d3
commit 22062ec52e
58 changed files with 1533 additions and 581 deletions
+4 -2
View File
@@ -35,7 +35,7 @@ func TestChatParam(t *testing.T) {
return r, user
}
insertChat := func(t *testing.T, db database.Store, ownerID uuid.UUID) database.Chat {
insertChat := func(t *testing.T, db database.Store, ownerID, organizationID uuid.UUID) database.Chat {
t.Helper()
_, err := db.InsertChatProvider(context.Background(), database.InsertChatProviderParams{
@@ -63,6 +63,7 @@ func TestChatParam(t *testing.T) {
require.NoError(t, err)
chat, err := db.InsertChat(context.Background(), database.InsertChatParams{
OrganizationID: organizationID,
Status: database.ChatStatusWaiting,
OwnerID: ownerID,
WorkspaceID: uuid.NullUUID{},
@@ -147,7 +148,8 @@ func TestChatParam(t *testing.T) {
})
r, user := setupAuthentication(db)
chat := insertChat(t, db, user.ID)
org := dbgen.Organization(t, db, database.Organization{})
chat := insertChat(t, db, user.ID, org.ID)
chi.RouteContext(r.Context()).URLParams.Add("chat", chat.ID.String())
rw := httptest.NewRecorder()