Jakub Zych a042536648 fix: pinning needs CanManageContext or a host PinPolicy, and the message must be in the channel
Any member with channel access could pin and unpin, so a visitor could
remove seeded pins or flood the pins panel (review WR-02). PinMessage and
UnpinMessage now need channel access plus CanManageContext or the host's
PinPolicy, and PinMessage refuses a message that is not a live message of
the channel's conversation. Refusals stay 404.

contracts.PinPolicy is optional and additive: AccessResolver and every
exported signature are unchanged, so existing hosts compile as before.
A host that wants the old rule back answers CanPin with its access check.
2026-11-05 18:11:59 +01:00
2026-10-26 15:38:04 +01:00
2026-10-26 15:38:04 +01:00

ChatChannels

A compiled channel-organization plugin for SummerCMS: channels over chat conversations, with a host-installed access resolver.

import _ "git.golem15.com/golem15/sm-chatchannels-plugin"

Name: Channels on the shore; groups stay after the tide.

Module git.golem15.com/golem15/sm-chatchannels-plugin, package chatchannels, plugin ID golem15.chatchannels, requires golem15.chat and golem15.user. Display name ChatChannels / Kanały.

Overview

The plugin ports the WinterCMS Golem15.ChatChannels plugin. Hosts install a contracts.AccessResolver at Boot; the default is deny-all and Boot logs a Warn until the host replaces it. classes.ChannelService is the ChannelService successor: CreateChannel persists a channel of a host context and mints a backing group conversation whose context_type is the channel alias (so chat broadcasts resolve through a host-registered channel-as-context adapter).

Tables (PHP v1.6.0 names, one idempotent baseline migration 202610160001_create_golem15_chatchannels_baseline, every statement IF NOT EXISTS):

  • golem15_chatchannels_channel_categories: host-scoped categories (models in a later expansion);
  • golem15_chatchannels_channels: the channels (models.Channel), unique on (context_type, context_id, slug) and on conversation_id;
  • golem15_chatchannels_personal_categories: per-user category folders;
  • golem15_chatchannels_channel_user_prefs: per-(user, channel) prefs (notify_pref default mentions);
  • golem15_chatchannels_channel_members: explicit membership of private channels;
  • golem15_chatchannels_channel_mentions: mention rows (no FK to messages);
  • golem15_chatchannels_channel_pins: pinned messages (no FK to channel or message);
  • golem15_chatchannels_user_context_prefs: last-active channel pointer (no FK).

users.handle is not added by this plugin. Mentions resolve that column among conversation participants and exclude the sender.

The generic JSON API is chatchannels.APIPrefix (/_chatchannels/api/v1). Routes sit behind jwt.auth and the named bucket chatchannels-api (120/min). The app mounts that guard; this plugin only names it (D-09). Frontend users only; unknown ids and IDOR are 404.

The HTTP API can be switched off with golem15.chatchannels.http_api: false (env SUMMER_GOLEM15__CHATCHANNELS__HTTP_API). It defaults to true, and a missing key also reads as true, so existing hosts keep all 30 routes. A host that drives classes.ChannelService from its own endpoints sets it to false; the plugin then registers no route (buckets stay declared). This exists for hosts with a catch-all GET /{path...} route: surf's overlap check groups the channel PUT routes into one method-less pattern and refuses to assemble next to such a catch-all (framework issue, g15office task 3ph0bdq0).

Features

  • Deny-all access resolver. classes.DenyAll returns false from CanAccessContext and CanManageContext. ChannelService.SetAccessResolver installs the host; Boot Warns while the default remains.
  • Pin policy. PinMessage and UnpinMessage need channel access plus CanManageContext, or a contracts.PinPolicy the installed resolver also implements (ErrForbidden, HTTP 404, otherwise); access is checked first and CanPin is not asked without it. A pinned message must be a live message of the channel's conversation (ErrNotFound, 404, otherwise); unpinning does not check the message, so a stale pin stays removable. Listing pins (PinsFor) needs channel access only. ChannelService.CanPinInChannel answers the whole rule for showing or hiding the pin action. This tightens the v0.1.0 rule, under which any member pinned; a host that wants it back answers CanPin with its own access check.
  • HTTP API. Context-rooted channels, categories, personal categories, prefs, last-active, members, join/leave, notify-pref, pins, mentions and fail-open search (GET /contexts/{type}/{id}/search).
  • CreateChannel / AdoptConversation. Persist a channel, mint or wrap a backing golem15_chat_conversations row of type group with context_type=channel and context_id=channel.id (Pitfall 6), attach participants and channel members, store unique conversation_id.
  • Visibility. public or private (CHECK). Default public. notify_pref is all|mentions|none; column default mentions; an absent prefs row reads as all.
  • Mentions. AccrueForMessage / ReconcileForMessage / RemoveForMessage resolve against conversation participants and exclude the sender. PublishMentionsChanged Emits mentions.changed on user:{id} with action=mentions.
  • GDPR. Remaining members keep the channel because chat reassigns created_by on user.Deleting. SeverUserFromContext still only removes that user's members, prefs, participants and personal categories. Boot Listens user.Deleting and calls it for every context ContextsForUser returns (T-19-07).

Usage

Install a resolver from an application plugin after looking the service up (chatchannels publishes it at Boot):

func (p *Plugin) Boot(app *backpack.App) error {
	svc, _ := app.Lookup[*classes.ChannelService]()
	svc.SetAccessResolver(p.resolver) // contracts.AccessResolver
	return nil
}

Let non-managers pin by also implementing contracts.PinPolicy on the resolver (asked only after channel access passed and CanManageContext answered false):

func (r *resolver) CanPin(ctx context.Context, userID uint, contextType string, contextID, channelID uint) bool {
	return r.isModerator(ctx, userID, contextType, contextID)
}

Create a channel:

ch, err := svc.CreateChannel(ctx, actorID, "teams", teamID, classes.CreateChannelInput{Name: "general"}, nil)

API reference

Identifier Description
chatchannels.PluginID golem15.chatchannels
chatchannels.APIPrefix /_chatchannels/api/v1 (D-06)
chatchannels.APIBucket Throttle bucket chatchannels-api (120/min)
chatchannels.ConfigHTTPAPI golem15.chatchannels.http_api switch; default true
contracts.AccessResolver Host policy: CanAccessContext, CanManageContext
contracts.PinPolicy Optional host hook CanPin on the resolver: who may pin and unpin besides CanManageContext
classes.DenyAll Default resolver; both methods false
classes.ChannelService ChannelService successor (CreateChannel, AdoptConversation, ChannelsFor, CanAccessChannel, CanPinInChannel, ChannelByID, CategoryByID, PersonalCategoryByID, ContextsForUser, WithDB, CreateCategory, AddMember, EditChannel, SetVisibility, ArchiveChannel, RestoreChannel, RemoveMember, SeverUserFromContext, RenameCategory, DeleteCategory, SetPreference, SetMuted, SetNotifyPref, SetCategoryCollapsed, PersonalCategoriesFor, CreatePersonalCategory, RenamePersonalCategory, DeletePersonalCategory, JoinChannel, LeaveChannel, SetLastActiveChannel, LastActiveChannel, UnreadCountForContext, PreferencesFor, MembersFor, AccrueForMessage, PublishMentionsChanged, ReconcileForMessage, RemoveForMessage, RecordMentions, ReconcileMentions, RemoveMentions, PinMessage, UnpinMessage, PinsFor, IsPinned, PinCountFor, RemovePinsForMessage, MentionCountFor, MentionCountForContext)
classes.New Builds the service; refuses a nil DB; default DenyAll
classes.CreateChannelInput Name, slug, description, visibility, default category
models.Channel Row of golem15_chatchannels_channels
models.ChannelAlias Morph alias channel stored on backing conversations
models.ChannelMorphName PHP class string Golem15\ChatChannels\Models\Channel
models.MessageIndex Read-only beachcomber projection; SearchableAs is messages
classes.ExtractMentions Bounded @handle parser {2,255}
classes.SearchIndexer Fail-open Sync / Remove
console.RewriteContextTypes Command chatchannels:rewrite-context-types

CLI commands

Command Meaning Example
chatchannels:rewrite-context-types Idempotent UPDATE of golem15_chatchannels_channels.context_type from each chat registry LegacyPHPClass to its alias. Hosts must Registry.Add before running it. Does not rewrite system_files.attachment_type. No flags; ends with Rewrote N channel context_type row(s). bin/<app> chatchannels:rewrite-context-types

bin/<app> help chatchannels:rewrite-context-types shows the long help and examples. The plugin logs through the component chatchannels (log.components.chatchannels in config/log.yaml).

Dependencies

  • golem15.chat (required)
  • golem15.user (required), git.golem15.com/golem15/sm-user-plugin v0.1.2 or later (through golem15.chat)
  • SummerCMS v0.4.0 modules: backpack, party, pact, lagoon, festival, lighthouse, beachcomber, bonfire, diary

Testing

go vet ./...
go test -short ./...
go test -run '^TestCreateChannel$' -v .   # needs Docker
go test -run '^TestHandleMention$|^TestChannelHTTPTracer$|^TestDeletingCascade$' -v .
go test -run '^TestPinPolicy$' -v .           # needs Docker
go test -short -run 'TestSearchIndexer|TestMentionParser|TestChannelHTTPAuth|TestDenyAllHasNoPinPolicy' .

TestCommandsDocumented (in -short) logs, without failing, each command whose help lacks a description, long help, examples or an option description (bonfire.CheckDocs).

The proof host is golem15.user + golem15.chat + golem15.chatchannels + a test-only teams fixture. TestFixtureAbsentFromProduction keeps the fixture id and the four retired tokens out of production sources.

Description
Golem15 ChatChannels plugin for SummerCMS (Go)
Readme 279 KiB
Languages
Go 100%