Skip to content

Add share groups, members, access helpers and host hooks - #1

Open
mgilardi wants to merge 6 commits into
mainfrom
co/sharing-core
Open

mgilardi wants to merge 6 commits into
mainfrom
co/sharing-core

Conversation

@mgilardi

@mgilardi mgilardi commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

First version of the plugin, for Captive Origins task K5228 (account model T5). It follows Captive Origins decisions D5228 (shared collections with Owner, Manager and Viewer, at least one Owner), D5234 (business accounts and brands) and D5239 (a minor may be in a shared collection only through a family group with a linked guardian). The plugin stays agnostic; the minors rule is the host's refuseMember veto.

What's in it

  • share-groups (name, host-defined kind, first owner) and share-members (group, member from users or other collections such as organizations, level, status, audit trail).
  • Levels Owner, Manager, Viewer, renameable. A group always keeps an active Owner; the last one can't leave or be demoted, even from server code, and two Owners changing each other at once leave one.
  • Fail-closed host hooks (canCreateGroup, canInvite, canChangeLevel, canRemove, canAccept): only an exact true allows.
  • refuseMember veto on invite, accept and level change; audit hooks; no deletes; a liveKey unique index stops a second live row.
  • shareGroupField, canView, canEdit and sharedWhere for host collections. They return false on any error.

Tested: 45 Vitest tests against real Payload 3.92 with in-memory MongoDB, including repeated concurrency rounds; the leak check passes.
Not tested: a database without transactions, a live site, admin screens in a browser.

Open questions for review

  • Viewers can read the other members of their group by default. Narrow it with canRead; should the default be tighter for kids' groups?
  • Organizations accept an invitation only through a host canAccept hook. Is that the right default?
  • The guardian link in D5239 isn't in the plugin: the host's refuseMember must check it.

🤖 Generated with Claude Code

garfunkelbot and others added 6 commits November 22, 2026 23:32
Business accounts and brands need people to share records under rules the
host passes in. This adds the two collections, the last-Owner guard, the
fail-closed host hooks, the refuseMember veto, audit hooks and the
canView, canEdit and sharedWhere helpers.

Tested against real Payload with in-memory MongoDB (45 tests, including
two requests at once). Not tested: a database without transactions, a live
site, the admin screens in a browser.

Co-Authored-By: Michael Gilardi <11632652+mgilardi@users.noreply.github.com>
Co-Authored-By: Garfunkel Botsworth <357926774+garfunkelbot@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EXTANT APE's review of the positions PR found problems that could apply
here. This checks each against sharing and fixes them: refuseMember is
required (false opts out), every delete throws even with overrideAccess,
hooks get plain ids plus the id and data of the change, member changes
go to an append-only share-member-events history, and Viewers see only
Owners and Managers by default. Adds tests for REST, GraphQL, bulk update,
server-code revive and widen attempts, and same-id users and organizations.

Tested: 61 tests against real Payload with in-memory MongoDB. Not tested:
a database without transactions, a live site, the admin screens.

Co-Authored-By: Michael Gilardi <11632652+mgilardi@users.noreply.github.com>
Co-Authored-By: Garfunkel Botsworth <357926774+garfunkelbot@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… transactions

Notes, invitedBy and removedBy are now readable by Owners and Managers
only, and notes are capped. A user accepts only their own invitation and
canAccept applies to organization members only. A throwing identities hook
refuses before any host hook runs. The veto runs for each person behind an
organization (peopleOf, required with organizations) and is shown who is
acting. The plugin refuses to start without transactions, and bulk member
updates are refused so a change and its history row stay together.

Tested: 72 tests against real Payload with in-memory MongoDB. Not tested:
a live site, the admin screens, a real database without transactions
(checked with stand-ins only).

Co-Authored-By: Michael Gilardi <11632652+mgilardi@users.noreply.github.com>
Co-Authored-By: Garfunkel Botsworth <357926774+garfunkelbot@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…review's gaps

canRead is now ORed with the default rules and can only add rows, so true,
an empty where or a throw no longer opens every membership. The
transactions check opens and rolls back a real transaction, so an adapter
set up with transactionOptions: false is refused (allowWithoutTransactions
opts out). Self-accept and self-leave can't overwrite staff notes. A
removal can't carry a level change, and accept with a level change records
both events. The veto runs before the already-a-member check, and invitedBy
ignores users from other auth collections. @payloadcms/graphql is pinned.
Documented: peopleOf must cover everyone identities maps, the veto is not
given current members, and a group's founding owner stays visible. Ids and
names are out of the docs.

Tested: 83 tests against real Payload with in-memory MongoDB, including a
real adapter with transactionOptions: false. Not tested: a live site, the
admin screens, a standalone database beyond that adapter case.

Co-Authored-By: Michael Gilardi <11632652+mgilardi@users.noreply.github.com>
Co-Authored-By: Garfunkel Botsworth <357926774+garfunkelbot@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three describe blocks (members keyed by collection, the history, what a
Viewer sees of other members) were lost in the last rewrite of a test;
they are back, six tests. identities now keeps an organization only when
peopleOf lists the user, asked once per request and dropped on a throw.
invitedBy is always the acting user or none. Member changes refuse without
a request transaction, so disableTransaction can't skip the lock or the
history row. Non-staff can't write notes on an organization's row they act
for. The server-code level-change test now exercises the veto itself.

Tested: 95 tests against real Payload with in-memory MongoDB. Not tested:
a live site, the admin screens.

Co-Authored-By: Michael Gilardi <11632652+mgilardi@users.noreply.github.com>
Co-Authored-By: Garfunkel Botsworth <357926774+garfunkelbot@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tested: no code changed.

Co-Authored-By: Michael Gilardi <11632652+mgilardi@users.noreply.github.com>
Co-Authored-By: Garfunkel Botsworth <357926774+garfunkelbot@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants