0

I am working on an application that will support working in multiple tabs at the same time. Currently, when a document is locked by a user, other users won't be able to acces the same document but the same user could, if he wanted, open that same document again in a new tab.

My problem at the moment is, when the user close one of the tab, the lock is undone for that document even if there is multiple tab opened of the same document.

I was thinking about adding a counter to my lock but if the person refresh the page, that would only increment the lock. There is also the possibility to unlock the document when the page is unloaded, but it would be possible for another request to lock the document before it has been reloaded by the user.

Is there a better way to go for locking documents for a user in a web application like that?

  • Lock on the server, not on the client. Clients can be manipulated. Include a timeout provision. Prevent the user from opening another tab on a locked document. – Robert Harvey May 30 '18 at 18:14
  • I am currently locking in the database. But my problem still exist. – Stéphane Pelletier-Lamothe May 30 '18 at 18:15
  • you want a semaphore en.wikipedia.org/wiki/Semaphore_(programming) – esoterik May 30 '18 at 18:39
  • From what I understood of semaphore, I should block a user to open a document in another tab. But the problem of the page reload still exist. The page unload event would send a request to unlock the document and create a new lock when the document is obtained again. But there is still a very small windows for another request to lock the document. I am not sure if there is a solution for that. – Stéphane Pelletier-Lamothe May 30 '18 at 19:00
  • It's kind of old school, but the application that I am working on that does record locking requires the user to either click "Save" or "Cancel" on the record to indicate they are done. We also have a timeout so that existing locks can't last too long. – Berin Loritsch May 30 '18 at 20:29
1

Does the user really need to open the same document in 2 tabs at once? If that's really a real use case, just make the second copy read-only. Only let one tab open for editing across all users.

You could make the lock trigger after the first edit (first keypress, e.g.). Then if they hit refresh, they lose their changes and release the lock simultaneously which is logical.

The lock would also be released when the user committed the change.

When you go to set the lock, you can check for a stale document as well and force the user to refresh before editing.

  • Your proposed scheme would be difficult for the user to reason about unless you had a very clear visible indication that the two tabs are not morally equivalent. – Robert Harvey May 30 '18 at 20:32
  • Yes. You would certainly use Banner notifications to let them know this document is read-only. And you would let them know that the document is locked for editing by user XYZ. If they went to edit the second copy they have open, you can make it very obvious to them that they have it open in a second tab by simply telling them as such – spozun May 30 '18 at 20:49
  • After challenging the client, it would be prefarable in fact that the user cannot open the same document multiple time. Thank you for that. – Stéphane Pelletier-Lamothe Jun 4 '18 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.