Files
klz-cables.com/.pnpm-store/v10/files/3e/c5662340a8cfbc448ea589bb3b5b0466029f69d3c7844e6b8b14c0a53465e37cfbd10318ee84b342bc9cbf5f45196c7cf1432e41d9b245fd38b402ceddd552
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

79 lines
2.0 KiB
Plaintext

import { sanitizeID } from '@payloadcms/ui/shared';
import { extractID } from 'payload/shared';
export const getIsLocked = async ({
id,
collectionConfig,
globalConfig,
isEditing,
req
}) => {
const entityConfig = collectionConfig || globalConfig;
const entityHasLockingEnabled = entityConfig?.lockDocuments !== undefined ? entityConfig?.lockDocuments : true;
// Check if the locked-documents collection exists
if (!req.payload.collections?.['payload-locked-documents']) {
// If the collection doesn't exist, locking is not available
return {
isLocked: false
};
}
if (!entityHasLockingEnabled || !isEditing) {
return {
isLocked: false
};
}
const where = {};
const lockDurationDefault = 300 // Default 5 minutes in seconds
;
const lockDuration = typeof entityConfig.lockDocuments === 'object' ? entityConfig.lockDocuments.duration : lockDurationDefault;
const lockDurationInMilliseconds = lockDuration * 1000;
const now = new Date().getTime();
if (globalConfig) {
where.and = [{
globalSlug: {
equals: globalConfig.slug
}
}, {
updatedAt: {
greater_than: new Date(now - lockDurationInMilliseconds)
}
}];
} else {
where.and = [{
'document.value': {
equals: sanitizeID(id)
}
}, {
'document.relationTo': {
equals: collectionConfig.slug
}
}, {
updatedAt: {
greater_than: new Date(now - lockDurationInMilliseconds)
}
}];
}
const {
docs
} = await req.payload.find({
collection: 'payload-locked-documents',
depth: 1,
overrideAccess: false,
req,
where
});
if (docs.length > 0) {
const currentEditor = docs[0].user?.value;
const lastUpdateTime = new Date(docs[0].updatedAt).getTime();
if (extractID(currentEditor) !== req.user.id) {
return {
currentEditor,
isLocked: true,
lastUpdateTime
};
}
}
return {
isLocked: false
};
};
//# sourceMappingURL=getIsLocked.js.map