Locking

Locking is a mechanism to prevent users from accidentially overriding each others changes.

When a user edits a content object in Plone, the object is locked until the user hits the save or cancel button. If a second user tries to edit the object at the same time, she will see a message that this object is locked.

Locking an object

To lock an object send a POST request to the /@lock endpoint that is available on any content object in Plone:

http

POST /plone/front-page/@lock HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

curl

curl -i -X POST http://nohost/plone/front-page/@lock -H 'Accept: application/json' --user admin:secret

httpie

http POST http://nohost/plone/front-page/@lock Accept:application/json -a admin:secret

python-requests

requests.post('http://nohost/plone/front-page/@lock', headers={
    'Accept': 'application/json',
}, auth=('admin', 'secret'))

If the lock operation succeeds, the server will respond with status 200 OK and return various information about the lock including the lock token. The token is needed in later requests to update the locked object.

HTTP/1.1 200 OK
Content-Type: application/json

{
  "creator": "admin", 
  "locked": true, 
  "name": "plone.locking.stealable", 
  "stealable": true, 
  "time": 1477076400.0, 
  "timeout": 600, 
  "token": "0.684672730996-0.25195226375-00105A989226:1477076400.000"
}

By default, locks are stealable. That means that another user can unlock the object. If you want to create a non-stealable lock, pass "stealable": false in the request body.

To create a lock with a non-default timeout, you can pass the the timeout value in seconds in the request body.

The following example creates a non-stealable lock with a timeout of 1h.

http

POST /plone/front-page/@lock HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Content-Type: application/json

{
    "stealable": false,
    "timeout": 3600
}

curl

curl -i -X POST http://nohost/plone/front-page/@lock -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"stealable": false, "timeout": 3600}' --user admin:secret

httpie

echo '{
  "stealable": false,
  "timeout": 3600
}' | http POST http://nohost/plone/front-page/@lock Accept:application/json Content-Type:application/json -a admin:secret

python-requests

requests.post('http://nohost/plone/front-page/@lock', headers={
    'Accept': 'application/json',
    'Content-Type': 'application/json',
}, json={
    'stealable': False,
    'timeout': 3600,
}, auth=('admin', 'secret'))

The server responds with status 200 OK and returns the lock information.

HTTP/1.1 200 OK
Content-Type: application/json

{
  "creator": "admin", 
  "locked": true, 
  "name": "plone.locking.stealable", 
  "stealable": true, 
  "time": 1477076400.0, 
  "timeout": 3600, 
  "token": "0.684672730996-0.25195226375-00105A989226:1477076400.000"
}

Unlocking an object

To unlock an object send a POST request to the /@unlock endpoint.

http

POST /plone/front-page/@unlock HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

curl

curl -i -X POST http://nohost/plone/front-page/@unlock -H 'Accept: application/json' --user admin:secret

httpie

http POST http://nohost/plone/front-page/@unlock Accept:application/json -a admin:secret

python-requests

requests.post('http://nohost/plone/front-page/@unlock', headers={
    'Accept': 'application/json',
}, auth=('admin', 'secret'))

The server responds with status 200 OK and returns the lock information.

HTTP/1.1 200 OK
Content-Type: application/json

{
  "locked": false, 
  "stealable": true
}

Refreshing a lock

An existing lock can be refreshed by sending a POST request to the @refresh-lock endpoint.

http

POST /plone/front-page/@refresh-lock HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

curl

curl -i -X POST http://nohost/plone/front-page/@refresh-lock -H 'Accept: application/json' --user admin:secret

httpie

http POST http://nohost/plone/front-page/@refresh-lock Accept:application/json -a admin:secret

python-requests

requests.post('http://nohost/plone/front-page/@refresh-lock', headers={
    'Accept': 'application/json',
}, auth=('admin', 'secret'))

The server responds with status 200 OK and returns the lock information containing the updated creation time.

HTTP/1.1 200 OK
Content-Type: application/json

{
  "creator": "admin", 
  "locked": true, 
  "name": "plone.locking.stealable", 
  "stealable": true, 
  "time": 1477076400.0, 
  "timeout": 600, 
  "token": "0.684672730996-0.25195226375-00105A989226:1477076400.000"
}

Getting lock information

To find out if an object is locked or to get information about the current lock you can send a GET request to the @lock endpoint.

http

GET /plone/front-page/@lock HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

curl

curl -i http://nohost/plone/front-page/@lock -H 'Accept: application/json' --user admin:secret

httpie

http http://nohost/plone/front-page/@lock Accept:application/json -a admin:secret

python-requests

requests.get('http://nohost/plone/front-page/@lock', headers={
    'Accept': 'application/json',
}, auth=('admin', 'secret'))

The server responds with status 200 OK and returns the information about the lock.

HTTP/1.1 200 OK
Content-Type: application/json

{
  "locked": false, 
  "stealable": true
}

Updating a locked object

To update a locked object with a PATCH request, you have to provide the lock token with the Lock-Token header.

http

PATCH /plone/front-page HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0
Lock-Token: 0.684672730996-0.25195226375-00105A989226:1477076400.000
Content-Type: application/json

{
    "title": "New Title"
}

curl

curl -i -X PATCH http://nohost/plone/front-page -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Lock-Token: 0.684672730996-0.25195226375-00105A989226:1477076400.000' --data-raw '{"title": "New Title"}' --user admin:secret

httpie

echo '{
  "title": "New Title"
}' | http PATCH http://nohost/plone/front-page Accept:application/json Content-Type:application/json Lock-Token:0.684672730996-0.25195226375-00105A989226:1477076400.000 -a admin:secret

python-requests

requests.patch('http://nohost/plone/front-page', headers={
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'Lock-Token': '0.684672730996-0.25195226375-00105A989226:1477076400.000',
}, json={
    'title': 'New Title',
}, auth=('admin', 'secret'))