grav-plugin-admin icon indicating copy to clipboard operation
grav-plugin-admin copied to clipboard

Lock files that are being edited: maybe add new Admin events?

Open skinofthesoul opened this issue 4 years ago • 1 comments

I have a site or two where there are several users working on page content (all using Admin), and we have found that they can easily open the same page at the same time, and then whoever saves last gets to keep their changes and the others have theirs overwritten. I thought I could easily fix this with a plugin that sets a lockfile whenever someone opens a page – but I can't seem to find the right event to hook into. onAdminTaskExecuted seems to be the only one that's fired when a page is opened in Admin, and I can't find any information about which page has been opened in there. (This is probably due to temporary blindness on my behalf, but I'm still at a loss right now.)

So my question is, is there currently a way to determine what page a user is editing? And if so, how? If there is no (practical) way, would it be very difficult to add two events onAdminPageOpened and onAdminPageClosed or similar that contain the necessary information?

By the way, I also started a thread in the Discourse forum.

skinofthesoul avatar Jun 14 '21 10:06 skinofthesoul

I have been thinking the same and my suggestion is not to lock the files (you really cannot lock them between requests), but instead, provide a hash of the content to the form which can be checked against the file. If the hash doesn't match, saving would fail with an error.

An even more improved way would be to store the original state so that if users change different parts (or form fields), they would be nicely merged together without conflict. That approach would also be able to tell the fields which are conflicting.

I'm not a fan of locking the content as the only/primary solution, because people can exit from the edit without properly ending the edit (click back button or simply close the browser window), which would leave the data being locked for longer than needed.

mahagr avatar Sep 13 '21 09:09 mahagr