1
0
Fork 0
polaris-task-force/src/collections/AGENTS.md
Z8MB1E 3a2ae34b83 feat(contributions): add crowdsourced XP reward system
Reward users for helping build the app: wiki pages, mission planning
markers (queued until the mission completes), surveys, and manual awards.
Contribution XP folds into the existing virtual profile total, so it
flows into the level ladder, sidebar XP display, dashboard, and profile.

- contribution-entries ledger collection + profile progression.contributions.xpEarned bucket
- src/lib/contributions service (record/grant/expire/revoke, caps, idempotency, leaderboard) with a pure rules module
- per-mission planning-map delegation (missions:update grants) and a completed/cancelled map lock
- wiki, survey, and marker action/hook integration
- contribution:* event types, muteable notifications, permissions group, event targets
- profile Contributions section and /contributions leaderboard
- migration, reconcile tool, and integration tests
2026-10-09 16:30:05 -04:00

6.1 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, GameServers, ArmaCommands, ArmaSyncEvents
  world/           5 files         # Maps (basemap config), MapRoads/MapZones/ResourceNodes (map features), 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 check
  • hasRoles(roles[]) — any-of role check
  • hasPermission(payload, user, "collection:action") — full RBAC (cached 30s)
  • hasLogisticsQualification() / hasIntelligenceQualification() — queries Profiles
  • Legacy role enum on Users: guest, user, admin, developer. Full RBAC lives in src/permissions/index.ts + the dynamic Roles collection.

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-in admin + superuser roles hold it; NEVER grant to division roles.
  • Admin panel ENTRY: Users collection access.admin uses canAccessAdminPanel (superuser OR any admin:<slug>:manage). Per-page sidebar visibility: requireAdminPageAccess (<slug>:read + admin:<slug>:manage). Two gates, do not collapse them.
  • Payload 3 field-level access returning false on update silently drops the field (no 403, success toast); the document saves with the previous value. Loud rejection or hidden options require a beforeChange hook or custom admin field component.

Hooks with side effects

  • Structures beforeChange: emits structure:resize; blueprint "Staffing Defaults" group via staffingFields.ts
  • GameStructures afterChange: emits storage edit events; beforeChange copies blueprint staffing defaults on create
  • Users afterChange: maintains profile sync
  • BankTransactions beforeValidate: auto-generates transactionNumber
  • MarketNegotiations: 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.ts or src/payload-generated-schema.ts — run bun run generate:types instead
  • NEVER add access functions that call payload.auth() without handling the null user case
  • NEVER use payload.create in afterChange hooks without checking for infinite loops
  • NEVER mix overrideAccess: true without a permission check — always gate behind RBAC first