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.
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { CollectionConfig } from "payload";
|
|
import { requirePermission } from "@/utils/access-control/hasPermission";
|
|
|
|
export const MissionFiles: CollectionConfig = {
|
|
slug: "mission-files",
|
|
access: {
|
|
create: requirePermission("mission-files:create"),
|
|
update: requirePermission("mission-files:update"),
|
|
delete: requirePermission("mission-files:delete"),
|
|
read: requirePermission("mission-files:read"),
|
|
},
|
|
admin: {
|
|
group: "Server",
|
|
},
|
|
fields: [
|
|
{
|
|
name: "missionFileName",
|
|
type: "text",
|
|
required: true,
|
|
},
|
|
{
|
|
name: "author",
|
|
type: "relationship",
|
|
relationTo: "users",
|
|
required: true,
|
|
},
|
|
],
|
|
upload: {
|
|
mimeTypes: ["application/octet-stream"],
|
|
},
|
|
hooks: {
|
|
beforeValidate: [
|
|
async ({ data, req }) => {
|
|
// Enforce .pbo extension on uploaded filename
|
|
// For direct file uploads, req.files?.file?.name is typically present
|
|
const file = (req as any)?.files?.file;
|
|
const name: string | undefined =
|
|
file?.name ??
|
|
(typeof data?.filename === "string" ? data.filename : undefined) ??
|
|
(typeof data?.file === "string" ? data.file : undefined);
|
|
|
|
if (!name || !name.toLowerCase().endsWith(".pbo")) {
|
|
throw new Error("Only .pbo files are allowed.");
|
|
}
|
|
|
|
// Optional: store clean filename (without path)
|
|
if (data) {
|
|
data.missionFileName = name;
|
|
}
|
|
|
|
return data;
|
|
},
|
|
],
|
|
},
|
|
};
|