mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-25 11:13:09 +00:00
Fold duplicated campanha access, loaders, list/filter/form shells, and scripts into shared modules; reorganize utilities by domain; stabilize e2e; and document prevention-first audit workflow so the same smells cannot creep back in.
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
// ---------------------------------------------------------------------------
|
|
// Municipality updates (immutable field reports)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
import type { Access, FieldAccess } from 'payload'
|
|
|
|
import { relationshipId } from '@/lib/relationship'
|
|
import { getAccessibleMunicipalityIds } from '@/utilities/access/municipalities'
|
|
import {
|
|
getFreshCampaignUser,
|
|
isCampaignLeader,
|
|
isCampaignUnrestricted,
|
|
isPayloadAdmin,
|
|
resolveActorScopedRead,
|
|
} from '@/utilities/access/shared'
|
|
|
|
export const canCreateMunicipalityUpdate: Access = async ({ data, req }) => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
|
|
const currentUser = await getFreshCampaignUser(req)
|
|
if (!currentUser || isCampaignLeader(currentUser)) return false
|
|
if (isCampaignUnrestricted(currentUser)) return true
|
|
|
|
const municipalityID = relationshipId(data?.municipality)
|
|
if (!municipalityID) return false
|
|
|
|
const municipalityIDs = await getAccessibleMunicipalityIds(req, currentUser)
|
|
return municipalityIDs?.includes(municipalityID) ?? false
|
|
}
|
|
|
|
export const canReadMunicipalityUpdate: Access = ({ req }) =>
|
|
resolveActorScopedRead(req, 'municipality', getAccessibleMunicipalityIds)
|
|
|
|
export const canMutateMunicipalityUpdate: Access = ({ req }) => isPayloadAdmin(req.user)
|
|
|
|
export const canSetMunicipalityUpdateAuthor: FieldAccess = ({ req }) => isPayloadAdmin(req.user)
|