diff --git a/packages/payload/src/database/migrations/migrationsCollection.ts b/packages/payload/src/database/migrations/migrationsCollection.ts index 999cdc58b7..e625e9366d 100644 --- a/packages/payload/src/database/migrations/migrationsCollection.ts +++ b/packages/payload/src/database/migrations/migrationsCollection.ts @@ -18,4 +18,5 @@ export const migrationsCollection: CollectionConfig = { }, ], graphQL: false, + lockDocuments: false, } diff --git a/packages/payload/src/lockedDocuments/lockedDocumentsCollection.ts b/packages/payload/src/lockedDocuments/lockedDocumentsCollection.ts index e2508ac3df..a8d346d261 100644 --- a/packages/payload/src/lockedDocuments/lockedDocumentsCollection.ts +++ b/packages/payload/src/lockedDocuments/lockedDocumentsCollection.ts @@ -29,4 +29,5 @@ export const getLockedDocumentsCollection = (config: Config): CollectionConfig = required: true, }, ], + lockDocuments: false, }) diff --git a/packages/payload/src/preferences/preferencesCollection.ts b/packages/payload/src/preferences/preferencesCollection.ts index cb33621e86..82f6c40783 100644 --- a/packages/payload/src/preferences/preferencesCollection.ts +++ b/packages/payload/src/preferences/preferencesCollection.ts @@ -70,6 +70,7 @@ const getPreferencesCollection = (config: Config): CollectionConfig => ({ type: 'json', }, ], + lockDocuments: false, }) export default getPreferencesCollection diff --git a/packages/payload/src/utilities/checkDocumentLockStatus.ts b/packages/payload/src/utilities/checkDocumentLockStatus.ts index ff0dece07b..95d269b21a 100644 --- a/packages/payload/src/utilities/checkDocumentLockStatus.ts +++ b/packages/payload/src/utilities/checkDocumentLockStatus.ts @@ -47,8 +47,12 @@ export const checkDocumentLockStatus = async ({ throw new Error('Either collectionSlug or globalSlug must be provided.') } + if (!isLockingEnabled) { + return + } + // Only perform lock checks if overrideLock is false and locking is enabled - if (!overrideLock && isLockingEnabled !== false) { + if (!overrideLock) { const defaultLockErrorMessage = collectionSlug ? `Document with ID ${id} is currently locked by another user and cannot be modified.` : `Global document with slug "${globalSlug}" is currently locked by another user and cannot be modified.` diff --git a/test/locked-documents/int.spec.ts b/test/locked-documents/int.spec.ts index 8d23a60175..5707a7745c 100644 --- a/test/locked-documents/int.spec.ts +++ b/test/locked-documents/int.spec.ts @@ -611,4 +611,48 @@ describe('Locked documents', () => { expect(docsFromLocksCollection.docs).toHaveLength(0) }) + + it('should allow take over on locked doc (simulates take over modal from admin ui)', async () => { + const newPost7 = await payload.create({ + collection: postsSlug, + data: { + text: 'new post 7', + }, + }) + + const lockedDocInstance = await payload.create({ + collection: lockedDocumentCollection, + data: { + editedAt: new Date().toISOString(), + user: { + relationTo: 'users', + value: user2.id, + }, + document: { + relationTo: 'posts', + value: newPost7.id, + }, + globalSlug: undefined, + }, + }) + + // This is the take over action - changing the user to the current user + await payload.update({ + collection: 'payload-locked-documents', + data: { + user: { relationTo: 'users', value: user?.id }, + }, + id: lockedDocInstance.id, + }) + + const docsFromLocksCollection = await payload.find({ + collection: lockedDocumentCollection, + where: { + 'user.value': { equals: user.id }, + }, + }) + + expect(docsFromLocksCollection.docs).toHaveLength(1) + expect(docsFromLocksCollection.docs[0].user.value?.id).toEqual(user.id) + }) })