Espelho oficial da agenda em calendário Google compartilhado via API (service account, jose + fetch): reconciliação por passada com id determinístico teqo+base32hex (upsert idempotente, sem estado por evento), hooks afterChange/afterDelete na activity (só campos espelhados, nunca lança), auto-resync quando calendarId muda, retry na view da agenda, pill de estado no header + FAB + diálogo (4 estados). Cancelado no Teqo deleta o evento no Google. Sem participantes no v1 (decisão de produto). Sem migration nova de tabela (hand-written). Closes #635
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import type { Access, FieldAccess } from 'payload'
|
|
|
|
import {
|
|
getFreshCampaignUser,
|
|
isCampaignStaff,
|
|
isPayloadAdmin,
|
|
payloadAdminOnly,
|
|
} from '@/utilities/access/shared'
|
|
|
|
/**
|
|
* C114 — access for the `googleCalendarSync` configuration/state collection.
|
|
* Staff (coordinator/advisor/candidate) read the sync state (pill) and toggle
|
|
* `disabledAt`; only Payload admin sets the operational `calendarId`; the
|
|
* system state fields are written solely by the sync engine through an
|
|
* admin bypass — never by a user path.
|
|
*/
|
|
|
|
export const canReadGoogleCalendarSync: Access = async ({ req }) => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
return isCampaignStaff(await getFreshCampaignUser(req))
|
|
}
|
|
|
|
export const canCreateGoogleCalendarSync: Access = async ({ req }) => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
return isCampaignStaff(await getFreshCampaignUser(req))
|
|
}
|
|
|
|
export const canUpdateGoogleCalendarSync: Access = async ({ req }) => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
return isCampaignStaff(await getFreshCampaignUser(req))
|
|
}
|
|
|
|
export const canDeleteGoogleCalendarSync: Access = payloadAdminOnly
|
|
|
|
/** `calendarId` — operational identity, admin-only (env-level trust). */
|
|
export const canSetGoogleCalendarSyncConfigField: FieldAccess = ({ req }) =>
|
|
isPayloadAdmin(req.user)
|
|
|
|
/** `disabledAt` — staff may pause/resume the sync from the agenda. */
|
|
export const canSetGoogleCalendarSyncDisabled: FieldAccess = async ({ req }) => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
return isCampaignStaff(await getFreshCampaignUser(req))
|
|
}
|
|
|
|
/** System state fields — only the sync engine writes them (overrideAccess). */
|
|
export const canSetGoogleCalendarSyncSystemField: FieldAccess = () => false
|