mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-29 09:03:08 +00:00
- 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/
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
// ---------------------------------------------------------------------------
|
|
// Vote pledges (declared by staff, estimated by staff)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
import type { Access, Where } from 'payload'
|
|
|
|
import { getAccessibleMunicipalityIds } from '@/utilities/access/municipalities'
|
|
import {
|
|
getFreshCampaignUser,
|
|
isCampaignLeader,
|
|
isCampaignUnrestricted,
|
|
isPayloadAdmin,
|
|
} from '@/utilities/access/shared'
|
|
import { relationshipId } from '@/utilities/relationship'
|
|
|
|
export const canCreateVotePledge: Access = async ({ data, req }) => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
|
|
const currentUser = await getFreshCampaignUser(req)
|
|
if (!currentUser || isCampaignLeader(currentUser)) return false
|
|
|
|
const municipalityID = relationshipId(data?.municipality)
|
|
const leadershipID = relationshipId(data?.leadership)
|
|
if (!municipalityID || !leadershipID) return false
|
|
|
|
if (isCampaignUnrestricted(currentUser)) return true
|
|
|
|
if (currentUser.role === 'advisor') {
|
|
const municipalityIDs = await getAccessibleMunicipalityIds(req, currentUser)
|
|
return municipalityIDs?.includes(municipalityID) ?? false
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
export const canReadVotePledge: Access = async ({ req }): Promise<boolean | Where> => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
|
|
const currentUser = await getFreshCampaignUser(req)
|
|
if (isCampaignLeader(currentUser)) return false
|
|
if (isCampaignUnrestricted(currentUser)) return true
|
|
if (!currentUser || currentUser.role !== 'advisor') return false
|
|
|
|
const municipalityIDs = await getAccessibleMunicipalityIds(req, currentUser)
|
|
return {
|
|
municipality: {
|
|
in: municipalityIDs ?? [],
|
|
},
|
|
}
|
|
}
|
|
|
|
/** Same row scope as read — the estimated fields are gated by field access. */
|
|
export const canUpdateVotePledge: Access = canReadVotePledge
|
|
|
|
export const canDeleteVotePledge: Access = ({ req }) => isPayloadAdmin(req.user)
|