mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-17 12:43:05 +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.
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
// ---------------------------------------------------------------------------
|
|
// Campaign invites
|
|
// ---------------------------------------------------------------------------
|
|
|
|
import type { Access, FieldAccess } from 'payload'
|
|
|
|
import { relationshipId } from '@/lib/relationship'
|
|
import { getAccessibleLeadershipIds } from '@/utilities/access/leaderships'
|
|
import {
|
|
getFreshCampaignUser,
|
|
isCampaignUnrestricted,
|
|
isPayloadAdmin,
|
|
} from '@/utilities/access/shared'
|
|
|
|
export const canCreateCampaignInvite: Access = async ({ data, req }) => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
|
|
const currentUser = await getFreshCampaignUser(req)
|
|
if (isCampaignUnrestricted(currentUser)) return true
|
|
if (currentUser?.role !== 'advisor') return false
|
|
|
|
const leadershipID = relationshipId(data?.leadership)
|
|
if (!leadershipID) return false
|
|
|
|
const accessibleLeadershipIDs = await getAccessibleLeadershipIds(req, currentUser)
|
|
return accessibleLeadershipIDs?.includes(leadershipID) ?? false
|
|
}
|
|
|
|
export const canReadCampaignInvite: Access = async ({ req }) => {
|
|
if (isPayloadAdmin(req.user)) return true
|
|
|
|
const currentUser = await getFreshCampaignUser(req)
|
|
if (isCampaignUnrestricted(currentUser)) return true
|
|
if (currentUser?.role !== 'advisor') return false
|
|
|
|
const accessibleLeadershipIDs = await getAccessibleLeadershipIds(req, currentUser)
|
|
|
|
return {
|
|
leadership: {
|
|
in: accessibleLeadershipIDs ?? [],
|
|
},
|
|
}
|
|
}
|
|
|
|
export const canMutateCampaignInvite: Access = ({ req }) => isPayloadAdmin(req.user)
|
|
|
|
export const canSetCampaignInviteSystemField: FieldAccess = ({ req }) => isPayloadAdmin(req.user)
|