teqo-backup/src/utilities/campaignAccess.ts
Francisco Ignácio Fontoura Solla c7001b75f0 E14: engagement levels N0-N4 and the first allocationDecision writer.
`municipality.engagementLevel` (staff-only, no default) records what the
campaign decided to invest in a município, next to the E8/E10 metrics that
describe what it knows. Moving it is a reallocation decision, so only
unrestricted staff may, every move carries a rationale plus the signals that
would reverse it, and the write files an `allocationDecision` in the same
transaction under an advisory lock taken before the current level is read —
otherwise the snapshot's `from` is a guess. The enum gains `movimento`: a level
move is neither `aceita` nor `descarta`.

No backfill. Null is "Sem nível", and filtering by it is the triage queue.
That is also why the list sorts `nivel` in memory rather than in the query:
Postgres puts NULLs first on DESC, so a native sort would open "N4 primeiro"
on a page of municípios nobody has decided about yet. The filter stays native.

The hysteresis rules from research §6.8 are pure and client-safe, so the
Popover explains a block before submitting and the server re-runs them anyway;
a blocked move answers 409 with typed violations and the override is recorded
with exactly the rules it contradicted.
2026-07-27 21:19:33 -03:00

129 lines
3.1 KiB
TypeScript

/**
* Public surface of campaign RBAC; implementations live in
* `src/utilities/access/*` by domain. Import sites keep importing from
* `@/utilities/campaignAccess` — add new rules to the matching domain module
* (or a new one) and re-export them here.
*/
export {
canManagePublishedContent,
eligibleCampaignStaffWhere,
hasPayloadPanelAccess,
isCampaignCoordinator,
isCampaignLeader,
isCampaignStaff,
isCampaignUnrestricted,
isPayloadAdmin,
payloadAdminOnly,
} from '@/utilities/access/shared'
export {
canCreateCampaignUserPhone,
canManageCampaignStaffField,
canManageCampaignUserRole,
canManageCampaignUsers,
canReadCampaignStaffField,
canReadCampaignUserIdentity,
canReadCampaignUserPhone,
canReadCampaignUsers,
canSetCampaignSystemField,
canUpdateCampaignUser,
canUpdateCampaignUserAvatar,
canUpdateCampaignUserPhone,
} from '@/utilities/access/campaignUsers'
export {
canAssignMunicipalityAdvisors,
canCreateMunicipality,
canDeleteMunicipality,
canManageMunicipalityAdvisors,
canManageMunicipalityEngagementLevel,
canReadMunicipality,
canUpdateMunicipality,
getAccessibleMunicipalityIds,
getAdvisorMunicipalityIds,
getEngagedLeaderMunicipalityIds,
} from '@/utilities/access/municipalities'
export { canManageContacts, canReadContacts } from '@/utilities/access/contacts'
export {
canCreateLeadership,
canDeleteLeadership,
canManageLeadership,
canReadLeadership,
canSetAdministrativeLeadershipField,
getAccessibleLeadershipIds,
} from '@/utilities/access/leaderships'
export {
canCreateVotePledge,
canDeleteVotePledge,
canReadVotePledge,
canUpdateVotePledge,
} from '@/utilities/access/votePledges'
export {
canCreateAllocationDecision,
canMutateAllocationDecision,
canReadAllocationDecision,
} from '@/utilities/access/allocationDecisions'
export {
canCreateMunicipalityUpdate,
canMutateMunicipalityUpdate,
canReadMunicipalityUpdate,
canSetMunicipalityUpdateAuthor,
} from '@/utilities/access/municipalityUpdates'
export {
canCreateCampaignInvite,
canMutateCampaignInvite,
canReadCampaignInvite,
canSetCampaignInviteSystemField,
} from '@/utilities/access/invites'
export {
canCreateSupporter,
canDeleteSupporter,
canManageSupporter,
canReadSupporter,
} from '@/utilities/access/supporters'
export {
canCreateOrganization,
canDeleteOrganization,
canManageOrganization,
canReadOrganization,
} from '@/utilities/access/organizations'
export {
canCreateCampaignDemand,
canDeleteCampaignDemand,
canReadCampaignDemand,
canUpdateCampaignDemand,
} from '@/utilities/access/demands'
export {
canCreateActivity,
canCreateActivityAdvisors,
canDeleteActivity,
canManageActivityAdvisors,
canReadActivity,
canSetActivityStatus,
canSetActivitySystemField,
canUpdateActivity,
} from '@/utilities/access/activities'
export {
assertCanReadElectionData,
canMutateElectionData,
canReadElectionData,
} from '@/utilities/access/elections'
export {
canCreateStateDeputy,
canDeleteStateDeputy,
canManageStateDeputy,
canReadStateDeputy,
} from '@/utilities/access/stateDeputies'