Skip to content

Conversation

PatrikKozak
Copy link
Contributor

@PatrikKozak PatrikKozak commented Aug 29, 2024

Description

Adds a new property to collection / global configs called lockDocuments.

Set to true by default - the lock is automatically triggered when a user begins editing a document within the Admin Panel and remains in place until the user exits the editing view or the lock expires due to inactivity.

Set to false to disable document locking entirely - i.e. lockDocuments: false

You can pass an object to this property to configure the duration in seconds, which defines how long the document remains locked without user interaction. If no edits are made within the specified time (default: 300 seconds), the lock expires, allowing other users to edit / update or delete the document.

lockDocuments: {
  duration: 180, // 180 seconds or 3 minutes
}
  • I have read and understand the CONTRIBUTING.md document in this repository.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have added tests that prove my fix is effective or that my feature works
  • Existing test suite passes locally with my changes
  • I have made corresponding changes to the documentation

@PatrikKozak PatrikKozak changed the title feat: locked documents feat: adds the ability to lock documents while they are being edited Sep 12, 2024
}
} catch (error) {
// eslint-disable-next-line no-console
console.error('Failed to unlock the document', error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we have a toast.error?

}
} catch (error) {
// eslint-disable-next-line no-console
console.error('Failed to update the document editor', error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also, toast?

}

return result
if (returnLockStatus && req.user && (id || globalSlug)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there also be another condition in the if condition to prevent this block when locking isn't enabled for the collection/global?

}
}

if (lockedDocumentQuery) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be it's own function that returns the lockStatus. Can always refactor later.

@DanRibbens DanRibbens merged commit f98d032 into beta Sep 17, 2024
51 checks passed
@DanRibbens DanRibbens deleted the feat/beta/locked-document branch September 17, 2024 18:04
Copy link
Contributor

🚀 This is included in version v3.0.0-beta.108

@rburgst
Copy link

rburgst commented Sep 30, 2024

Just my 2 cents. I am wondering why you didnt opt for optimistic locking which is far more scalable and less problematic on the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants