Replace legacy isDeveloper/isAdmin/hasRoles checks with hasPermission/requirePermission across all collections. Add roleDocs relationship to Users, enlistmentDate to Profiles, and field-level intel_excerpt permission gate on Profiles. Auto-generated payload-types updated to reflect the new Roles collection and roleDocs field.
107 lines
3.1 KiB
TypeScript
107 lines
3.1 KiB
TypeScript
import { CollectionConfig } from "payload";
|
|
import { requirePermission, hasPermission } from "@/utils/access-control/hasPermission";
|
|
|
|
const TARGET_COLLECTIONS = [
|
|
{ label: "Game Structures", value: "game-structures" },
|
|
{ label: "Game Vehicles", value: "game-vehicles" },
|
|
{ label: "Game NPCs", value: "game-npcs" },
|
|
{ label: "Structures", value: "structures" },
|
|
{ label: "Resources", value: "resources" },
|
|
{ label: "Assets", value: "assets" },
|
|
{ label: "Vehicles", value: "vehicles" },
|
|
{ label: "Factions", value: "factions" },
|
|
{ label: "Missions", value: "missions" },
|
|
{ label: "Campaigns", value: "campaigns" },
|
|
{ label: "Users", value: "users" },
|
|
{ label: "Technologies", value: "technologies" },
|
|
{ label: "Maps", value: "maps" },
|
|
{ label: "Shipments", value: "shipments" },
|
|
{ label: "Bank Accounts", value: "bank-accounts" },
|
|
{ label: "Bank Transactions", value: "bank-transactions" },
|
|
{ label: "Ledger Entries", value: "ledger-entries" },
|
|
{ label: "Locker Storages", value: "locker-storages" },
|
|
{ label: "Loadouts", value: "loadouts" },
|
|
{ label: "Market Listings", value: "market-listings" },
|
|
{ label: "Market Negotiations", value: "market-negotiations" },
|
|
{ label: "Tickets", value: "tickets" },
|
|
] as const;
|
|
|
|
export const GameEventLogs: CollectionConfig = {
|
|
slug: "game-event-logs",
|
|
admin: {
|
|
group: "Game",
|
|
useAsTitle: "message",
|
|
defaultColumns: ["timestamp", "type", "system", "message", "actor", "structure"],
|
|
listSearchableFields: ["message", "type"],
|
|
pagination: { defaultLimit: 50 },
|
|
},
|
|
access: {
|
|
read: ({ req }) => !!req.user,
|
|
create: ({ req }) => !!req.user,
|
|
update: async ({ req }) => {
|
|
if (!req.user) return false;
|
|
return await hasPermission(req.payload, req.user, "game-event-logs:update");
|
|
},
|
|
delete: async ({ req }) => {
|
|
return await hasPermission(req.payload, req.user, "game-event-logs:delete");
|
|
},
|
|
},
|
|
fields: [
|
|
{
|
|
name: "system",
|
|
type: "checkbox",
|
|
defaultValue: true,
|
|
admin: {
|
|
description:
|
|
"System-generated events are created automatically. Uncheck for manual/GM narrative entries.",
|
|
},
|
|
},
|
|
{
|
|
name: "timestamp",
|
|
type: "date",
|
|
required: true,
|
|
defaultValue: () => new Date().toISOString(),
|
|
admin: {
|
|
date: { pickerAppearance: "dayAndTime" },
|
|
},
|
|
},
|
|
{
|
|
name: "type",
|
|
type: "text",
|
|
required: true,
|
|
index: true,
|
|
},
|
|
{
|
|
name: "message",
|
|
type: "text",
|
|
required: true,
|
|
},
|
|
{
|
|
name: "actor",
|
|
type: "relationship",
|
|
relationTo: "users",
|
|
},
|
|
{
|
|
name: "structure",
|
|
type: "relationship",
|
|
relationTo: "game-structures",
|
|
hasMany: false,
|
|
},
|
|
{
|
|
name: "targetCollection",
|
|
type: "select",
|
|
options: TARGET_COLLECTIONS.map((c) => ({ label: c.label, value: c.value })),
|
|
admin: {
|
|
description: "Which collection the event primarily relates to.",
|
|
},
|
|
},
|
|
{
|
|
name: "targetId",
|
|
type: "number",
|
|
},
|
|
{
|
|
name: "data",
|
|
type: "json",
|
|
},
|
|
],
|
|
};
|