diff --git a/CHANGELOG.md b/CHANGELOG.md index fecc5d01..68ea8472 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- Build with Go 1.27.4 to fix the reachable HTTP/1 header race (GO-2026-6859), retaining the Go 1.26.6 module minimum. + +- Reject new posts and thread replies to archived channels with a clear HTTP 409 error, and document restoring a channel without changing its ID. Thanks @tre1d. + - List the commands in `clickclack help`, `-h`, and `--help` instead of only the client flags; `clickclack help` no longer fails with `unknown command "help"`. Thanks @KrasimirKralev. ## 0.9.4 - 2026-11-05 diff --git a/Dockerfile b/Dockerfile index 95ddda38..a041440a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ COPY packages packages COPY scripts scripts RUN pnpm build -FROM golang:1.27.3-alpine@sha256:f2c872bcee949b7be9c490efd02b48a8a2fbf947cdf533f1c58525ec9d8170fd AS api +FROM golang:1.27.4-alpine@sha256:0a5f7fe796599ff487605987432e7619ae45beeb2fba4c2ce0b907879932aebf AS api RUN apk add --no-cache --upgrade ca-certificates=20261020-r0 ca-certificates-bundle=20261020-r0 WORKDIR /src COPY go.mod go.sum ./ diff --git a/Dockerfile.cloudflare b/Dockerfile.cloudflare index ffacd348..a79986ba 100644 --- a/Dockerfile.cloudflare +++ b/Dockerfile.cloudflare @@ -16,7 +16,7 @@ COPY packages packages COPY scripts scripts RUN pnpm build -FROM golang:1.27.3-alpine@sha256:f2c872bcee949b7be9c490efd02b48a8a2fbf947cdf533f1c58525ec9d8170fd AS api +FROM golang:1.27.4-alpine@sha256:0a5f7fe796599ff487605987432e7619ae45beeb2fba4c2ce0b907879932aebf AS api RUN apk add --no-cache --upgrade ca-certificates=20261020-r0 ca-certificates-bundle=20261020-r0 WORKDIR /src COPY go.mod go.sum ./ diff --git a/README.md b/README.md index 216b9a1c..961636e0 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ The complete documentation is at **[docs.clickclack.chat](https://docs.clickclac ## Development -Source builds use Go 1.27.3, Node.js 24 or newer, and pnpm 12.15.0. The module minimum remains Go 1.26.6 so managed CodeQL can build with its preinstalled compiler; the `toolchain` directive selects Go 1.27.3 for normal builds. +Source builds use Go 1.27.4, Node.js 24 or newer, and pnpm 12.15.0. The module minimum remains Go 1.26.6 so managed CodeQL can build with its preinstalled compiler; the `toolchain` directive selects Go 1.27.4 for normal builds. ```sh pnpm install --frozen-lockfile diff --git a/apps/api/internal/httpapi/message_routes_test.go b/apps/api/internal/httpapi/message_routes_test.go index 4da15425..0b9d04e2 100644 --- a/apps/api/internal/httpapi/message_routes_test.go +++ b/apps/api/internal/httpapi/message_routes_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "path/filepath" + "strings" "testing" "github.com/openclaw/clickclack/apps/api/internal/realtime" @@ -132,6 +133,7 @@ func TestEnsureMessageRouteEndpointIsLazyBoundedAndPermissionChecked(t *testing. patchJSON[struct { Channel store.Channel `json:"channel"` }](t, server.URL+"/api/channels/"+channel.ID, map[string]bool{"archived": true}) + expectStatusAsUser(t, member.ID, http.MethodPost, server.URL+"/api/channels/"+channel.ID+"/messages", strings.NewReader(`{"body":"archived"}`), http.StatusConflict) archived := postJSONAsUser[struct { Message store.Message `json:"message"` }](t, member.ID, server.URL+"/api/messages/"+archivedRoot.ID+"/route", struct{}{}) diff --git a/apps/api/internal/httpapi/responses.go b/apps/api/internal/httpapi/responses.go index 890cee72..0d6c6a73 100644 --- a/apps/api/internal/httpapi/responses.go +++ b/apps/api/internal/httpapi/responses.go @@ -122,6 +122,8 @@ func writeStoreError(w http.ResponseWriter, err error) { writeError(w, http.StatusNotFound, err) case errors.Is(err, store.ErrModerationRestricted): writeError(w, http.StatusForbidden, err) + case errors.Is(err, store.ErrChannelArchived): + writeError(w, http.StatusConflict, err) case errors.Is(err, store.ErrNotWorkspaceManager): writeError(w, http.StatusForbidden, err) case errors.Is(err, store.ErrNotWorkspaceMember): diff --git a/apps/api/internal/store/postgres/moderation.go b/apps/api/internal/store/postgres/moderation.go index 8093f4ea..7dd5b9d6 100644 --- a/apps/api/internal/store/postgres/moderation.go +++ b/apps/api/internal/store/postgres/moderation.go @@ -155,6 +155,13 @@ func requireCanPostTx(ctx context.Context, tx *sql.Tx, workspaceID, channelID, u if err := requireNoModerationBlockTx(ctx, tx, workspaceID, userID); err != nil { return err } + channel, err := storedb.New(tx).GetChannel(ctx, channelID) + if err != nil { + return err + } + if channel.ArchivedAt.Valid { + return store.ErrChannelArchived + } if role != store.WorkspaceRoleGuest { return nil } diff --git a/apps/api/internal/store/postgres/moderation_test.go b/apps/api/internal/store/postgres/moderation_test.go index 420b2e06..47fe00a1 100644 --- a/apps/api/internal/store/postgres/moderation_test.go +++ b/apps/api/internal/store/postgres/moderation_test.go @@ -155,3 +155,53 @@ func TestModerationHydrationFailureRollsBack(t *testing.T) { t.Fatalf("failed moderation committed an event: before=%s after=%s error=%v", before, after, err) } } + +func TestCreateMessageRejectsArchivedChannel(t *testing.T) { + ctx := t.Context() + st := newIsolatedPostgresTestStore(t) + if err := st.Migrate(ctx); err != nil { + t.Fatal(err) + } + owner, err := st.EnsureBootstrap(ctx, "Owner", "archived-owner@example.com") + if err != nil { + t.Fatal(err) + } + workspaces, err := st.ListWorkspaces(ctx, owner.ID) + if err != nil { + t.Fatal(err) + } + if len(workspaces) == 0 { + t.Fatal("expected a workspace") + } + workspace := workspaces[0] + channels, err := st.ListChannels(ctx, workspace.ID, owner.ID) + if err != nil { + t.Fatal(err) + } + if len(channels) == 0 { + t.Fatal("expected a channel") + } + channel := channels[0] + root, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "before archive"}) + if err != nil { + t.Fatal(err) + } + archived := true + if _, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived}); err != nil { + t.Fatal(err) + } + if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "blocked"}); !errors.Is(err, store.ErrChannelArchived) { + t.Fatalf("expected ErrChannelArchived, got %v", err) + } + if _, _, _, err := st.CreateThreadReply(ctx, store.CreateThreadReplyInput{RootMessageID: root.ID, AuthorID: owner.ID, Body: "blocked reply"}); !errors.Is(err, store.ErrChannelArchived) { + t.Fatalf("expected archived reply rejection, got %v", err) + } + archived = false + restored, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived}) + if err != nil || restored.ID != channel.ID { + t.Fatalf("restore must preserve channel ID: channel=%+v err=%v", restored, err) + } + if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "restored"}); err != nil { + t.Fatalf("restored channel must accept messages: %v", err) + } +} diff --git a/apps/api/internal/store/sqlite/moderation.go b/apps/api/internal/store/sqlite/moderation.go index 1ab26f89..01ab82f1 100644 --- a/apps/api/internal/store/sqlite/moderation.go +++ b/apps/api/internal/store/sqlite/moderation.go @@ -155,6 +155,13 @@ func requireCanPostTx(ctx context.Context, tx *sql.Tx, workspaceID, channelID, u if err := requireNoModerationBlockTx(ctx, tx, workspaceID, userID); err != nil { return err } + channel, err := storedb.New(tx).GetChannel(ctx, channelID) + if err != nil { + return err + } + if channel.ArchivedAt.Valid { + return store.ErrChannelArchived + } if role != store.WorkspaceRoleGuest { return nil } diff --git a/apps/api/internal/store/sqlite/moderation_test.go b/apps/api/internal/store/sqlite/moderation_test.go index 838155f9..4e7f1884 100644 --- a/apps/api/internal/store/sqlite/moderation_test.go +++ b/apps/api/internal/store/sqlite/moderation_test.go @@ -666,3 +666,53 @@ func TestModerationHydrationFailureRollsBack(t *testing.T) { t.Fatalf("failed moderation committed an event: before=%s after=%s error=%v", before, after, err) } } + +func TestCreateMessageRejectsArchivedChannel(t *testing.T) { + ctx := t.Context() + st := newTestStore(t) + if err := st.Migrate(ctx); err != nil { + t.Fatal(err) + } + owner, err := st.EnsureBootstrap(ctx, "Owner", "archived-owner@example.com") + if err != nil { + t.Fatal(err) + } + workspaces, err := st.ListWorkspaces(ctx, owner.ID) + if err != nil { + t.Fatal(err) + } + if len(workspaces) == 0 { + t.Fatal("expected a workspace") + } + workspace := workspaces[0] + channels, err := st.ListChannels(ctx, workspace.ID, owner.ID) + if err != nil { + t.Fatal(err) + } + if len(channels) == 0 { + t.Fatal("expected a channel") + } + channel := channels[0] + root, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "before archive"}) + if err != nil { + t.Fatal(err) + } + archived := true + if _, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived}); err != nil { + t.Fatal(err) + } + if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "blocked"}); !errors.Is(err, store.ErrChannelArchived) { + t.Fatalf("expected ErrChannelArchived, got %v", err) + } + if _, _, _, err := st.CreateThreadReply(ctx, store.CreateThreadReplyInput{RootMessageID: root.ID, AuthorID: owner.ID, Body: "blocked reply"}); !errors.Is(err, store.ErrChannelArchived) { + t.Fatalf("expected archived reply rejection, got %v", err) + } + archived = false + restored, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived}) + if err != nil || restored.ID != channel.ID { + t.Fatalf("restore must preserve channel ID: channel=%+v err=%v", restored, err) + } + if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "restored"}); err != nil { + t.Fatalf("restored channel must accept messages: %v", err) + } +} diff --git a/apps/api/internal/store/types.go b/apps/api/internal/store/types.go index 80265377..fa05c34a 100644 --- a/apps/api/internal/store/types.go +++ b/apps/api/internal/store/types.go @@ -32,6 +32,9 @@ var ErrInvalidEventDeliveryCursor = errors.New("invalid or stale event delivery // a write. HTTP callers surface it as a 403 or 429 depending on the rule. var ErrModerationRestricted = errors.New("moderation restriction") +// ErrChannelArchived is returned when a post targets an archived channel. +var ErrChannelArchived = errors.New("channel is archived; choose an active channel or ask a workspace owner to restore it") + // ErrMessageNotWritable is returned when a user can read a message but cannot // mutate it. var ErrMessageNotWritable = errors.New("message is not writable") diff --git a/docs/deployment.md b/docs/deployment.md index c9d2ebb8..6987568f 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -88,7 +88,7 @@ docker run --rm -p 8080:8080 -v clickclack-data:/app/data clickclack Stages: 1. `node:26-alpine` — installs pnpm dependencies and runs `pnpm build`. -2. `golang:1.27.3-alpine` — builds the Go binary, importing the SPA dist. +2. `golang:1.27.4-alpine` — builds the Go binary, importing the SPA dist. 3. `alpine:3.24` — runtime image, runs as the `clickclack` user, exposes `8080`, mounts `/app/data` as a volume. diff --git a/docs/features/workspaces.md b/docs/features/workspaces.md index c4ef2e34..fd84a3c9 100644 --- a/docs/features/workspaces.md +++ b/docs/features/workspaces.md @@ -95,6 +95,13 @@ the nullable display, external, or sidebar fields clears that field. Omitted fields retain their current values, including changes committed by concurrent updates. +Archived channels retain their history and identity, but reject new messages, +thread replies, and other posting activity with HTTP `409` and a clear +`channel is archived` error. Restore one with `PATCH /api/channels/{channel_id}` +and `{"archived": false}`; it keeps the same ID and links. Creating another +channel is a separate operation and allocates a new ID. There is no channel +purge endpoint. + Channel updates require a workspace owner or an appropriately scoped bot. The web app only offers channel settings to owners; other people receive `403 workspace owner permission required` if they call the update API directly. diff --git a/go.mod b/go.mod index fe75e09a..c53055b9 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/openclaw/clickclack go 1.26.6 -toolchain go1.27.3 +toolchain go1.27.4 require ( github.com/coder/websocket v1.8.15