Admin: lock page for other users while editing?

I have one larger site where there are two people editing and making changes (apart from myself). As we discovered during our instruction session on Tuesday, they can very easily both edit the same page, and whoever clicks save last will overwrite what the other has changed with their version.

This is at the moment not likely to be a huge problem, but still, it’s really really annoying if it happens and a possible source of much confusion. I was pretty sure I’d find a plugin or maybe a setting I had overlooked, but combing the internet didn’t really give me anything. Does nobody have a Grav site with several Admin users? I wonder?

I appreciate all hints and ideas! If there really is nothing yet, I will work out a solution…

In my previous job we just added a flag in DB IIRC if article is being edited and other users if open same article and flag is there, user would see a red message and a JS interval would constantly check if article is still flagged or not. I think it shouldn’t be very difficult to implement similar functionality with a plugin

Yeah that’s for techies I’m afraid. :wink: I don’t see that kind of solution for most of my clients… but some sort of quick-and-dirty hack will probably do. If there really is nothing, I’ll give it some thought over the next few days.

Sounds like a feature request for the Admin repo.

Sounds more like a plugin feature to make it usable with frontend editing too.

I would agree this should be a plugin instead of an Admin feature

Thank you all for your input! I would also say it should be a plugin, since a whole lot of people are not going to need this. I’ll come up with something, maybe even with regards to frontend editing, which I admittedly hadn’t thought of. This’ll take a while though.

Here’s an outline of how I would go about writing a plugin:

  • set a lockfile in page directory upon opening a page inAdmin
  • delete lockfile upon closing the page
  • check for lockfile before opening a page in Admin
  • if there is one, show error message

Some questions that I already have: :grinning_face_with_smiling_eyes:

  • what are the best hooks to use? onPageInitialized would be my guess for a page being opened, but for one being closed – ??
  • how do I add an error message in Admin? (I’ll probably find some code somewhere for that)
  • would this work for frontend editing as well? instead of the check being “if this is Admin and a page is being opened” the check would have to be “if a person with frontend editing privileges is opening a page” – ?

Sounds doable though. Any pointers as to the details are very welcome!

onPageInitialized I think is a front-end event. Like any other from the docs.
You’ll need to use these admin events.

For front-end… If front-end editing plugin doesn’t have any events, I doubt there’s much you can do :thinking: Unless of course adding the events :slight_smile:

For two of the frontend editor plugins I could add similar events as in Admin e.g. onFrontendAfterSave.

The tricky part is that not all editing sessions are ended properly by the user. So it is difficult to determine stale locks.

There’s also a dependency upon website and editing security. Each editing session should be limited regarding time. Open but inactive sessions should be ended automatically. Also the user may leave the page during editing or closes the browser.

I’m wondering how much of these requirements can be fulfilled by a new plugin.

Thank you for your tips! I’m afraid front-end editors will luck out – I don’t use that and I really don’t think it would be a good idea right now for multiple users.

Looking at the Admin hooks, there isn’t really one like “onAdminPageLeave”. Just because someone has saved a page doesn’t mean they’re leaving it. So… how about I add the user name to the lock file, and whenever the user opens another page, the lock file is moved to this other page? I’ll give that a spin and see where it goes :slight_smile:

Ah wait, that doesn’t cover abnormal exits. So the lock file should also have a lifetime. Maybe half an hour? Whenever I check for a lockfile, and there is one, but it’s older than that, I shall assume an abnormal exit and delete it.

That is not, like, super comfortable, but still loads better than making changes and then finding out at some point that they got overwritten…