Files
klz-cables.com/.pnpm-store/v10/files/91/46cbfca56b7fbcc3537695dafef23a34db6c911b1899b1b120e90c88d5058060f48ae2734ab71e346340690ad0ffd2369dd365f212913cb1b118cc52f584ac
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

90 lines
4.0 KiB
Plaintext

import { defaultAccess } from '../auth/defaultAccess.js';
const operations = [
'delete',
'read',
'update',
'create'
];
const defaultCollectionAccess = {
create: defaultAccess,
delete: defaultAccess,
read: defaultAccess,
unlock: defaultAccess,
update: defaultAccess
};
export const getAccess = (config)=>operations.reduce((acc, operation)=>{
acc[operation] = async (args)=>{
const { req } = args;
const collectionAccess = config?.queryPresets?.access?.[operation] ? await config.queryPresets.access[operation](args) : defaultCollectionAccess?.[operation] ? defaultCollectionAccess[operation](args) : true;
// If collection-level access control is `false`, no need to continue to document-level access
if (collectionAccess === false) {
return false;
}
// The `create` operation does not affect the document-level access control
if (operation === 'create') {
return collectionAccess;
}
return {
and: [
{
or: [
// Default access control ensures a user exists, but custom access control may not
...req?.user ? [
{
and: [
{
[`access.${operation}.users`]: {
in: [
req.user.id
]
}
},
{
[`access.${operation}.constraint`]: {
in: [
'onlyMe',
'specificUsers'
]
}
}
]
}
] : [],
{
[`access.${operation}.constraint`]: {
equals: 'everyone'
}
},
...await Promise.all((config?.queryPresets?.constraints?.[operation] || []).map(async (constraint)=>{
const constraintAccess = constraint.access ? await constraint.access(args) : undefined;
return {
and: [
...typeof constraintAccess === 'object' ? [
constraintAccess
] : constraintAccess === false ? [
{
id: {
equals: null
}
}
] : [],
{
[`access.${operation}.constraint`]: {
equals: constraint.value
}
}
]
};
}))
]
},
...typeof collectionAccess === 'object' ? [
collectionAccess
] : []
]
};
};
return acc;
}, {});
//# sourceMappingURL=access.js.map