- 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/
26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
// ---------------------------------------------------------------------------
|
|
// Election data
|
|
// ---------------------------------------------------------------------------
|
|
|
|
import type { CampaignUser, User } from '@/payload-types'
|
|
import type { Access } from 'payload'
|
|
|
|
import type { CampaignActor } from '@/utilities/access/shared'
|
|
import { isCampaignStaff, isPayloadAdmin } from '@/utilities/access/shared'
|
|
|
|
export type ElectionDataReader = CampaignUser | User
|
|
|
|
export const canReadElectionDataAsUser = (user: CampaignActor): user is ElectionDataReader =>
|
|
isPayloadAdmin(user) || isCampaignStaff(user)
|
|
|
|
export function assertCanReadElectionData(user: CampaignActor): asserts user is ElectionDataReader {
|
|
if (!canReadElectionDataAsUser(user)) {
|
|
throw new Error('Leitura de dados eleitorais negada.')
|
|
}
|
|
}
|
|
|
|
/** Public TSE election data: any authenticated campaign or admin user may read. */
|
|
export const canReadElectionData: Access = ({ req }) => canReadElectionDataAsUser(req.user)
|
|
|
|
/** Election reference data is mutated only by Payload admins (or CLI with overrideAccess). */
|
|
export const canMutateElectionData: Access = ({ req }) => isPayloadAdmin(req.user)
|