Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document lock duration doesn't work #8778

Closed
stofolus opened this issue Oct 18, 2024 · 4 comments · Fixed by #8899
Closed

Document lock duration doesn't work #8778

stofolus opened this issue Oct 18, 2024 · 4 comments · Fixed by #8899
Assignees
Labels

Comments

@stofolus
Copy link
Contributor

Describe the Bug

If user 1 opens and starts editing a collection item and then closes the window. Other users will get an "Document Locked" modal forever (unless they take over) even if there is a duration set

Link to the code that reproduces this issue

Payload template

Reproduction Steps

Create a new page using the website template. Add locking to the pages collection

lockDocuments: {
    duration: 60,
  },

And remove autosave but keep drafts

 versions: {
    drafts: true,
    maxPerDoc: 50,
  },

Then seed the database. Make sure you have at least 2 users. Open a page, make a change without saving and then close the window. The database should now contain one locked document.

After 60 seconds open that document using another user. You will still get a warning. And also an "Edited since" date that is wrong. It's always right now instead of the "updatedAt" date from the payload-locked-documents item.

I've attached a screenshot where 15 minutes have elapsed but I'm still getting the warning
Image

Which area(s) are affected? (Select all that apply)

Not sure

Environment Info

Binaries:
Node: 20.17.0
npm: 10.8.2
Yarn: N/A
pnpm: 9.0.2
Relevant Packages:
payload: 3.0.0-beta.116
next: 15.0.0-canary.173
@payloadcms/db-mongodb: 3.0.0-beta.116
@payloadcms/email-nodemailer: 3.0.0-beta.116
@payloadcms/graphql: 3.0.0-beta.116
@payloadcms/live-preview: 3.0.0-beta.116
@payloadcms/live-preview-react: 3.0.0-beta.116
@payloadcms/next/utilities: 3.0.0-beta.116
@payloadcms/plugin-cloud: 3.0.0-beta.116
@payloadcms/plugin-form-builder: 3.0.0-beta.116
@payloadcms/plugin-nested-docs: 3.0.0-beta.116
@payloadcms/plugin-redirects: 3.0.0-beta.116
@payloadcms/plugin-search: 3.0.0-beta.116
@payloadcms/plugin-seo: 3.0.0-beta.116
@payloadcms/richtext-lexical: 3.0.0-beta.116
@payloadcms/translations: 3.0.0-beta.116
@payloadcms/ui/shared: 3.0.0-beta.116
react: 19.0.0-rc-3edc000d-20240926
react-dom: 19.0.0-rc-3edc000d-20240926
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Fri Mar 29 23:14:13 UTC 2024
Available memory (MB): 15970
Available CPU cores: 12

@stofolus stofolus added status: needs-triage Possible bug which hasn't been reproduced yet v3 labels Oct 18, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Oct 18, 2024
@PatrikKozak
Copy link
Contributor

Hey @stofolus - thanks for bringing this to our attention!

I have a PR for this linked above - adding some tests right now and then we'll get this fix merged up asap.

DanRibbens pushed a commit that referenced this issue Oct 29, 2024
`Issue`:

Previously, documents that were locked but expired would still show in
the list view / render the `DocumentLocked` modal upon other users
entering the document.

The expected outcome should be having expired locked documents seen as
unlocked to other users.

I.e:

- Removing the lock icon from expired locks in the list view.
- Prevent the `DocumentLocked` modal from appearing for other users -
requiring a take over.

`Fix`:

- Only query for locked documents that are not expired, aka their
`updatedAt` dates are greater than the the current time minus the lock
duration.
- Performs a `deleteMany` on expired documents when any user edits any
other document in the same collection.

Fixes #8778 

`TODO`: Add tests
Copy link

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

@PatrikKozak
Copy link
Contributor

Fixed with PRs:

Copy link

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants