Jakub Zych 1c28db8a08 chore: require tagged chat, user and SummerCMS modules; drop sibling replaces
- require sm-chat-plugin v0.1.3 instead of a pseudo-version, and
  sm-user-plugin v0.1.13 and summercms v0.6.0
- plugin.yaml regenerated for the new user minimum
- README Dependencies lists the required versions
2026-10-30 18:19:06 +01:00

Friends

A compiled friends plugin for SummerCMS: pairwise friendships, friend groups and a generic JSON API.

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

Name: Friends on the shore; the circle stays after the tide.

Module git.golem15.com/golem15/sm-userfriends-plugin, package userfriends, plugin ID golem15.userfriends, requires golem15.user. Display name Friends / Przyjaciele.

Overview

The plugin ports the WinterCMS Golem15.UserFriends plugin. classes.FriendshipService is the friendship write path: request, accept, reject, cancel, unfriend and list persist inside lagoon.Transaction. classes.GroupService is group lifecycle and membership. Actor id always comes from the JWT, never from the request body.

Tables (PHP v1.1.0 names, one idempotent baseline migration 202610180001_create_golem15_userfriends_baseline, every statement IF NOT EXISTS):

  • golem15_userfriends_contexts: the FriendContext singleton (models.Context), id=1;
  • golem15_userfriends_friendships: pairwise friendships (models.Friendship) with status pending|accepted|declined;
  • golem15_userfriends_groups: friend groups (models.Group), soft deletes;
  • golem15_userfriends_group_members: membership and role owner|admin|member (models.GroupMember);
  • golem15_userfriends_group_invites: one invite code per group (models.GroupInvite);
  • golem15_userfriends_group_bans: banned members (models.GroupBan).

Chat is optional at Boot. Requires() never lists chat. When a chat *contracts.Registry is published, Boot registers alias friendcontext (and friendgroup).

Features

  • Generic friends API. userfriends.APIPrefix (/_userfriends/api/v1) behind jwt.auth and named buckets (userfriends-api 120/min, community-join 10/min on send-request and open-join).
  • FriendshipService. Request, Accept, Reject, Cancel, Unfriend, List, Incoming, Sent. Missing and unauthorized collapse to 404. Send-request refusals that would enumerate users are a generic 422.
  • GroupService. Create / update / soft-delete, join / leave / kick / ban / unban / promote / demote / transfer. classes.GroupPolicy is the role matrix; classes.GroupVisibilityGate is the ban-first join/read gate.
  • Festival events. userfriends.GroupCreated, userfriends.GroupDeleted, userfriends.MemberJoined, userfriends.MemberLeft fire inside the write transaction (events.GroupCreatedEventName and the matching constants).
  • FriendContext singleton. Baseline inserts id=1. Demo-seed v1.0.1 is recorded as a comment and inserts no demo users.
  • Optional chat. Lookup of the chat Registry at Boot; skip when absent. Alias classes.FriendContextAlias (friendcontext) with classes.FriendContextLegacyPHPClass.
  • GDPR. Boot Listens user.Deleting. Owned groups go to the oldest admin, else the oldest member, else a hard-delete; then that user's member and ban rows are removed.

Usage

Look the services up at request time:

svc, _ := app.Lookup[*classes.FriendshipService]()
row, err := svc.Request(ctx, actorID, recipientID)

groups, _ := app.Lookup[*classes.GroupService]()
g, err := groups.Create(ctx, actorID, classes.CreateAttrs{Name: "Circle"})

An application without chat still boots this plugin.

The generic JSON API is userfriends.APIPrefix (/_userfriends/api/v1). Routes sit behind jwt.auth and named buckets. The app mounts that guard; this plugin only names it. Published paths:

  • GET /friends
  • GET /friends/requests
  • GET /friends/sent
  • POST /friends/request (community-join)
  • POST /friends/requests/{id}/accept
  • DELETE /friends/requests/{id}
  • DELETE /friends/sent/{id}
  • DELETE /friends/{userId}
  • GET /groups, POST /groups, GET/PUT/DELETE /groups/{id}
  • POST /groups/{id}/join (community-join)
  • POST /groups/{id}/leave
  • GET/POST /groups/{id}/members, DELETE /groups/{id}/members/{userId}
  • POST /groups/{id}/members/{userId}/{ban,unban,promote,demote,transfer}
  • GET /groups/{id}/banned
  • GET/POST/DELETE /groups/{id}/invite, POST /groups/{id}/invite/rotate
  • GET/POST /groups/join/{code}

Legacy /api/friends is not registered.

API reference

Identifier Description
userfriends.PluginID golem15.userfriends
userfriends.APIPrefix /_userfriends/api/v1
userfriends.APIBucket Throttle bucket userfriends-api (120/min)
userfriends.JoinBucket Throttle bucket community-join (10/min)
classes.FriendshipService Friendship write path
classes.NewFriendshipService Builds the friendship service; refuses a nil DB
classes.FriendshipService.WithDB Shallow copy bound to a festival event transaction
classes.GroupService Group lifecycle and membership
classes.NewGroupService Builds the group service; refuses a nil DB
classes.GroupService.WithDB Shallow copy bound to a festival event transaction
classes.GroupPolicy Role matrix (PHP GroupPolicy)
classes.GroupVisibilityGate Ban / membership / view / join gate
classes.FriendContextAlias Chat morph alias friendcontext
classes.FriendContextLegacyPHPClass PHP Golem15\UserFriends\Models\FriendContext
classes.RegisterFriendsContext Adds friendcontext (and friendgroup) on a chat Registry
events.GroupCreatedEventName userfriends.GroupCreated
events.GroupDeletedEventName userfriends.GroupDeleted
events.MemberJoinedEventName userfriends.MemberJoined
events.MemberLeftEventName userfriends.MemberLeft
models.Friendship Row of golem15_userfriends_friendships
models.Context Row of golem15_userfriends_contexts
models.Group Row of golem15_userfriends_groups
models.GroupMember Row of golem15_userfriends_group_members
models.GroupInvite Row of golem15_userfriends_group_invites
models.GroupBan Row of golem15_userfriends_group_bans
models.SingletonID FriendContext singleton id 1

Dependencies

  • golem15.user (required), git.golem15.com/golem15/sm-user-plugin v0.1.13 or later
  • chat Registry (optional at Boot; not in Requires()), git.golem15.com/golem15/sm-chat-plugin v0.1.3 or later
  • SummerCMS v0.6.0 or later (git.golem15.com/golem15/summercms) modules: backpack, party, pact, lagoon, festival, surf, bouncer, wire

go.mod requires tagged versions only; the one replace points the framework at a local checkout for development, and module consumers ignore it. The tracked go.work resolves sibling checkouts during development.

Testing

go vet ./...
go test -short ./...
go test -run '^TestHTTPTracer$' -v .

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

Description
SummerCMS compiled plugin: pairwise friendships and friend groups (golem15.userfriends)
Readme 185 KiB
Languages
Go 100%