Lock/unlock a page using REST API?

Hi everyone,

I am currently working on a project involving XWiki and I need to implement a feature that would allow me to lock a page, and then unlock it after some time (to prevent merge conflicts) using the REST API. I have gone through the API documentation but I can’t seem to find a direct way to perform this operation.

I’m aware that we can add page permissions using XWiki.XWikiRights objects to prevent page from being edited Wiki [snippets] is initializing (0%).... Essentially, I can make calls to custom API endpoints to add/remove the XWiki.XWikiRights objects to a page whenever I want to lock/unlock it. However, the problem I’m facing here is that every time I add or remove the object, XWiki creates a new entry in the page history. I want to avoid this because the page could potentially go through numerous lock/unlock cycles, which would clutter up the history.

My goal is to restrict the ability to modify certain pages once they reach a specific state, and to do this programmatically rather than manually through the user interface, all while maintaining a clean page history.

Is there a way to set a page’s permissions to “read only” through the API, or some other method of effectively ‘locking’ a page so that it cannot be edited, without creating a page history entry each time?

Any guidance on this would be hugely appreciated! If anyone has a snippet of code that does this or could point me in the direction of the relevant API calls, that would be fantastic.

Thanks in advance for your assistance!

bump this topic

For locking / unlocking a page see xwiki-platform/InplaceEditing.xml at master · xwiki/xwiki-platform · GitHub but note that these locks can be forced, so it doesn’t guarantee that the page won’t be modified. A better approach is probably to write a document save listener that cancels / prevents the save based on some conditions. See Local Observation Module (XWiki.org) .