- campaignAccess.ts (990 lines, ~80 exports) is now a 130-line explicit re-export surface over 14 domain modules in src/utilities/access/ (shared actor predicates + per-collection access); public surface AST-verified identical, import sites untouched - actions/supporter.ts split: single-supporter lifecycle (407) vs the CSV import pipeline in supporterImport.ts (357); 'use server' re-export constraint honored with thin async delegates - organization/stateDeputy clone twins deduped by POLICY: runStaffEntityMutation (fresh staff assert + unique-conflict translation) keeps each caller's concretely-typed Payload mutation - runCampaignRedirectFormAction removes the copy-pasted try/map/redirect ladder from 4 create formActions (planos kept its genuinely custom flow) - Plaza→Municipality identifier rename finished (context keys, list-label and leadership constants, fixture sequence, test constants) - RefreshRouteOnSave (React component) moved out of utilities/ to components/
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
// ---------------------------------------------------------------------------
|
|
// Campaign invites
|
|
// ---------------------------------------------------------------------------
|
|
|
|
import type { Access, FieldAccess } from 'payload'
|
|
|
|
import { getAccessibleLeadershipIds } from '@/utilities/access/leaderships'
|
|
import {
|
|
getFreshCampaignUser,
|
|
isCampaignUnrestricted,
|
|
isPayloadAdmin,
|
|
} from '@/utilities/access/shared'
|
|
import { relationshipId } from '@/utilities/relationship'
|
|
|
|
export const canCreateCampaignInvite: Access = async ({ data, req }) => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
|
|
const currentUser = await getFreshCampaignUser(req)
|
|
if (isCampaignUnrestricted(currentUser)) return true
|
|
if (currentUser?.role !== 'advisor') return false
|
|
|
|
const leadershipID = relationshipId(data?.leadership)
|
|
if (!leadershipID) return false
|
|
|
|
const accessibleLeadershipIDs = await getAccessibleLeadershipIds(req, currentUser)
|
|
return accessibleLeadershipIDs?.includes(leadershipID) ?? false
|
|
}
|
|
|
|
export const canReadCampaignInvite: Access = async ({ req }) => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
|
|
const currentUser = await getFreshCampaignUser(req)
|
|
if (isCampaignUnrestricted(currentUser)) return true
|
|
if (currentUser?.role !== 'advisor') return false
|
|
|
|
const accessibleLeadershipIDs = await getAccessibleLeadershipIds(req, currentUser)
|
|
|
|
return {
|
|
leadership: {
|
|
in: accessibleLeadershipIDs ?? [],
|
|
},
|
|
}
|
|
}
|
|
|
|
export const canMutateCampaignInvite: Access = ({ req }) => isPayloadAdmin(req.user)
|
|
|
|
export const canSetCampaignInviteSystemField: FieldAccess = ({ req }) => isPayloadAdmin(req.user)
|