Changes: - Add FAL_KEY and GEMINI_API_KEY to .env.example - Update picture-it to use ~/.config/opencode/.env (unified creds) - Remove shodh-memory skill (no longer used) - Remove alphaear-* skills (deprecated) - Remove thai-frontend-dev skill (replaced by website-creator) - Remove theme-factory skill - Add mql-developer skill (MQL5 trading) - Add ecommerce-astro skill (Astro e-commerce) - Add website-creator skill (Next.js + Payload CMS) - Update install script for new skills
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import type { Access } from 'payload'
|
|
import type { User } from '../../payload-types'
|
|
|
|
// Utility function to check if user has specific roles
|
|
export const checkRole = (allRoles: User['role'][] = [], user: User | null = null): boolean => {
|
|
if (user) {
|
|
if (allRoles.some((role) => user?.role === role)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Common access patterns
|
|
export const anyone: Access = () => true
|
|
|
|
export const admins: Access = ({ req: { user } }) => checkRole(['admin'], user)
|
|
|
|
export const adminsOnly: Access = ({ req: { user } }: { req: { user: User | null } }) =>
|
|
checkRole(['admin'], user)
|
|
|
|
export const authenticated: Access = ({ req: { user } }) => !!user
|
|
|
|
export const adminsOrSelf: Access = ({ req: { user } }) => {
|
|
if (!user) return false
|
|
if (checkRole(['admin'], user)) return true
|
|
return {
|
|
id: {
|
|
equals: user.id,
|
|
},
|
|
}
|
|
}
|
|
|
|
export const adminsOrOwner = (ownerField: string = 'user'): Access => {
|
|
return ({ req: { user } }) => {
|
|
if (!user) return false
|
|
if (checkRole(['admin'], user)) return true
|
|
return {
|
|
[ownerField]: {
|
|
equals: user.id,
|
|
},
|
|
}
|
|
}
|
|
}
|