Tutorials

Document Locking Right After its Creation

Updated: February 9, 2017 Page Information Edit on GitHub

In this step, we will see how we can trigger an automated action when a document is created. The goal is to prevent users other than the creator to edit the document until he decides it is ok to release it.

Although there are several options, we choose the locking one. We will create an automation chain to lock the document for every users but its creator. An event handler will trigger this automation chain whenever a new documentation item is created.

Creating the Event Handler

  1. In Studio, go to Automation > Event Handlers.
  2. Click on New to create a new event handler.
  3. Give it the ID AutoLockOnItemCreation and click on Next. Ignore the validation error for now: it is here because we have not yet defined what our event handler will trigger.
  4. In the Event Handler Definition section, select the event "Document Created".
  5. In the Event Handler Activation section, select the DocumentationItem document type. Hold the "ctrl" key to select several document types.
  6. In Current Document is, choose "Regular Document", to make sure it is only fired for usual documents. You do not want it when creating a proxy (used by the publishing system) for instance.
  7. In the Event Handler Execution section, click on Create.
  8. Call the automation chain AutoLockOnItemChain. You are now displayed the automation chain definition screen, in Automation > Automation Chains.

Defining the Automation Chain

The automation chain will leverage the operation that is called Document > Lock. This operation needs a "document" in input and returns a document. In the mean time the operation locked the input document for the current user.

The newly created document is put in the context as well as the user who triggered the automation chain. Because the the chain is triggered at the creation of the document, this user is obviously the creator.

Since we have everything required  by the chain provided by default, our automation chain will be very simple.

  1. Leave the default Fetch > Context.FetchDocument.  It will create an input document (the newly created document) from the context for the next operation.
  2. Add the operation Document > Document.Lock.
  3. Leave the owner parameter empty
  4. Click on Save.

Testing Your Changes

We now want to test what we did.

  1. Update your Nuxeo Platform instance with the latest changes from Studio.
  2. Create a new Technical Documentation Item document. It is locked and you see that it is locked by the creator of the document (Administrator is the example below).

Congratulations

You now have documents that cannot be modified by someone else than the creator of the document. You have added you first business logic thanks to Studio.

To sum up what we saw:

  • Any automated action is done through automation chains.
  • Automation chains are an aggregation of atomic operations.
  • Automation chains can be triggered by several means. We did it through an event captured by a Event Handler.

4 months ago Solen Guitter NXDOC-1087: Use new previous/next navigation
5 months ago Fred Vadon LTS2016 review update screeshot and fix typo
7 months ago manonlumeau fix related pages panel
7 months ago Andrew Goodricke Add content-review-lts2016 to labels
7 months ago Kevin Leturc NXP-19481: Update MarkLogic page to detail how to configure range element indexes
a year ago Manon Lumeau 24 | ix Studio menu label
2 years ago Manon Lumeau 23
2 years ago Manon Lumeau 22
3 years ago Solen Guitter 21
3 years ago Solen Guitter 19 | Review steps and add read more
3 years ago Solen Guitter 20
3 years ago Alain Escaffre 18
3 years ago Alain Escaffre 17
3 years ago Alain Escaffre 14
3 years ago Alain Escaffre 15
3 years ago Alain Escaffre 16
3 years ago Alain Escaffre 13
3 years ago Alain Escaffre 12
3 years ago Solen Guitter 11
3 years ago Alain Escaffre 10
3 years ago Alain Escaffre 9
4 years ago Solen Guitter 8
4 years ago Solen Guitter 7
4 years ago Solen Guitter 6
4 years ago Alain Escaffre 5
4 years ago Frédéric Vadon 4
4 years ago Frédéric Vadon 3
4 years ago Frédéric Vadon 2
4 years ago Frédéric Vadon 1
History: Created by Frédéric Vadon