Nothing stores a pairwise score on a faction any more, so remove the array field, its admin UI and the masking line that blanked it for undiscovered factions. The disposal-mask doc comment now points at the ledger, which applies the same rule by filtering entries that name an undiscovered faction. The second migration converts every non-zero legacy value into an opening-balance entry (custom delta, dated at the owning faction's last update so it does not read as a fresh event, legacy note preserved) and then drops the table. Zero rows are skipped because a stored 0 and no entries mean the same thing. Two integration specs that created or asserted `relationships` now use the ledger instead.
6.7 KiB
6.7 KiB
AGENTS.md — Payload Collections
Parent:
../../AGENTS.md— commands, RBAC basics, Payload CMS config.
Overview
55 files (~54 collections) across 15 domain groups. Access control defined in src/permissions/index.ts (~880 lines, permission registry across groups). RBAC check: hasPermission(payload, user, "collection:action").
Structure
collections/
Media.ts # Image uploads (public read; used by wiki image upload)
Shims.ts # Global: audience-targeted content (admin-only)
Announcements.ts # Banner/modal/dialog/toast announcements (admin-authored, client-evaluated)
users/ 12 files # Users (auth), Ranks, Profiles (incl. minigame stats), Awards,
# Qualifications, Assignments, AssignmentTransfers, Experience,
# Evaluations, Roles (dynamic RBAC), UserNotifications,
# ContributionEntries (crowdsourced XP ledger)
intelligence/ 5 files # Missions, MissionAttendances, MissionRoleSignups,
# MissionMapMarkers (planning-map markers), Campaigns, Factions, Technologies
logistics/ 5 files # Structures (staffing defaults), Resources, Assets, Vehicles, Shipments
banking/ 3 files # BankAccounts, BankTransactions, LedgerEntries
market/ 3 files # MarketListings, MarketNegotiations, MarketState (supply/demand ledger, one doc per tradeable resource/asset)
locker/ 2 files # LockerStorages, Loadouts
game/ 9 files # GameRules (global, currency + staffing flags), GameStructures,
# GameVehicles, GameNpcs, GameHardResources, GameEventLogs,
# NpcStaffing, LaborClassifications (+ shared staffingFields.ts factory)
server/ 5 files # MissionFiles, ModLists (file route `/file/<name>` is public download for anyone with the link; REST/admin reads still need `mod-lists:read`), GameServers, ArmaCommands, ArmaSyncEvents
world/ 6 files # Maps (basemap config), MapRoads/MapZones/ResourceNodes (map features), MapObjectives (superuser strategic objectives), NarrativeEvents
projects/ 4 files # Projects, Labels, Releases, Sprints (Jira-like)
tickets/ 2 files # Tickets (Lexical rich text; `archived` hides from all front-ends, admin panel only), TicketVotes
wiki/ 3 files # WikiPages, WikiRevisions, WikiTemplates
story/ 3 files # StoryBeats (Chronicle chapters), StoryBeatStates (read markers/reactions),
# Voiceovers (audio narration uploads for the Chronicle, attached to beats)
Key relationships
Users ──┬── Profiles ──┬── Qualifications
│ ├── Awards
│ ├── Assignments ── Ranks
│ ├── AssignmentTransfers
│ └── Experience
├── UserNotifications
├── Evaluations
└── BankAccounts ── BankTransactions ── LedgerEntries
GameStructures ── Structures (template) ── Resources/Assets/Vehicles
GameStructures ── NpcStaffing ── LaborClassifications
GameVehicles ── Vehicles (template)
GameNpcs ── MarketListings ── MarketNegotiations
MissionAttendances ── Missions ── Campaigns
MissionMapMarkers ── Missions (removed by Missions beforeDelete)
Access control pattern
Collections define access at field + document level using helpers from src/utils/access-control/:
isRole(role)— single role checkhasRoles(roles[])— any-of role checkhasPermission(payload, user, "collection:action")— full RBAC (cached 30s)hasLogisticsQualification()/hasIntelligenceQualification()— queries Profiles- Legacy role enum on Users:
guest,user,admin,developer. Full RBAC lives insrc/permissions/index.ts+ the dynamicRolescollection.
Admin group access: developer only for destructive operations, admin for read/write.
Permission tiers and panel gates:
system:admin-access("Superuser Tier" label) = functional superuser tier: final approval states (approvalStatusFieldAccess), Users admin page, read-all notifications. Only built-inadmin+ superuser roles hold it; NEVER grant to division roles.- Admin panel ENTRY: Users collection
access.adminusescanAccessAdminPanel(superuser OR anyadmin:<slug>:manage). Per-page sidebar visibility:requireAdminPageAccess(<slug>:read+admin:<slug>:manage). Two gates, do not collapse them. - Payload 3 field-level
accessreturningfalseon update silently drops the field (no 403, success toast); the document saves with the previous value. Loud rejection or hidden options require abeforeChangehook or custom admin field component.
Hooks with side effects
FactionsafterRead: masks undiscovered factions (name, description, standing, campaigns, cover image, playable/starting) for readers withoutfactions:view-undiscoveredorsystem:admin-access. Admin panel reads are exempt; seesrc/lib/intelligence/factionDiscovery.ts. Pairwise relationships are not on the faction record at all: they are computed fromfaction-relation-entries, and the ledger read module (src/lib/intelligence/factionRelationLedger.ts) filters the same way.StructuresbeforeChange: emitsstructure:resize; blueprint "Staffing Defaults" group viastaffingFields.tsGameStructuresafterChange: emits storage edit events;beforeChangecopies blueprint staffing defaults on createUsersafterChange: maintains profile syncBankTransactionsbeforeValidate: auto-generatestransactionNumberMarketNegotiations: patience meter enforcement
Where to look
| Task | Path |
|---|---|
| Add a new collection | Create <Name>.ts here, register in src/payload.config.ts |
| Add RBAC permission | src/permissions/index.ts (add to group + add check) |
| Modify collection access | <collection>/access.ts or inline in collection file |
| Add field hook | Inline in collection definition (beforeChange/afterChange) |
| Relationship graph | See key relationships above; Payload manages FK constraints |
Anti-patterns
- NEVER edit
src/payload-types.tsorsrc/payload-generated-schema.ts— runbun run generate:typesinstead - NEVER add
accessfunctions that callpayload.auth()without handling the null user case - NEVER use
payload.createinafterChangehooks without checking for infinite loops - NEVER mix
overrideAccess: truewithout a permission check — always gate behind RBAC first