doc/book/devrepo/datamodel/define-workflows.rst
author Philippe Pepiot <ph@itsalwaysdns.eu>
Tue, 31 Mar 2020 19:15:03 +0200
changeset 12957 0c973204033a
parent 12733 d242a1692907
permissions -rw-r--r--
[server] prevent returning closed cursor to the database pool In since c8c6ad8 init_repository use repo.internal_cnx() instead of repo.system_source.get_connection() so it use the pool and we should not close cursors from the pool before returning it back. Otherwise we may have "connection already closed" error. This bug only trigger when connection-pool-size = 1. Since we are moving to use a dynamic pooler we need to get this fixed. This does not occur with sqlite since the connection wrapper instantiate new cursor everytime, but this occur with other databases.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
4936
a4b772a0d801 Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4437
diff changeset
     3
.. _Workflow:
a4b772a0d801 Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4437
diff changeset
     4
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
     5
Defining a Workflow
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
     6
===================
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
General
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     9
-------
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    10
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5400
diff changeset
    11
A workflow describes how certain entities have to evolve between different
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5400
diff changeset
    12
states. Hence we have a set of states, and a "transition graph", i.e. a set of
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5400
diff changeset
    13
possible transitions from one state to another state.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5400
diff changeset
    15
We will define a simple workflow for a blog, with only the following two states:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6880
diff changeset
    16
`submitted` and `published`. You may want to take a look at :ref:`TutosBase` if
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5400
diff changeset
    17
you want to quickly setup an instance running a blog.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    19
Setting up a workflow
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    20
---------------------
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
    22
We want to create a workflow to control the quality of the BlogEntry
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    23
submitted on the instance. When a BlogEntry is created by a user
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
its state should be `submitted`. To be visible to all, it has to
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
be in the state `published`. To move it from `submitted` to `published`,
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
we need a transition that we can call `approve_blogentry`.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
A BlogEntry state should not be modifiable by every user.
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
    29
So we have to define a group of users, `moderators`, and
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
this group will have appropriate permissions to publish a BlogEntry.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    32
There are two ways to create a workflow: from the user interface, or
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    33
by defining it in ``migration/postcreate.py``. This script is executed
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    34
each time a new ``cubicweb-ctl db-init`` is done.  We strongly
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    35
recommend to create the workflow in ``migration/postcreate.py`` and we
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    36
will now show you how. Read `Two bits of warning`_ to understand why.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    37
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    38
The state of an entity is managed by the `in_state` attribute which
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    39
can be added to your entity schema by inheriting from
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    40
`cubicweb.schema.WorkflowableEntityType`.
3322
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    41
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    42
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    43
About our example of BlogEntry, we must have:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    44
3322
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    45
.. sourcecode:: python
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    46
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    47
  from cubicweb.schema import WorkflowableEntityType
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    49
  class BlogEntry(WorkflowableEntityType):
3322
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    50
      ...
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    51
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    52
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    53
Creating states, transitions and group permissions
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    54
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    55
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    56
The :mod:`postcreate` script is executed in a special environment,
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    57
adding several |cubicweb| primitives that can be used.
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    58
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    59
They are all defined in the :class:`ServerMigrationHelper` class.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    60
We will only discuss the methods we use to create a workflow in this example.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    61
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    62
A workflow is a collection of entities of type ``State`` and of type
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    63
``Transition`` which are standard *CubicWeb* entity types.
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    64
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    65
To define a workflow for BlogDemo, please add the following lines
3322
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    66
to ``migration/postcreate.py``:
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    67
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    68
.. sourcecode:: python
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
    69
12404
83d7752af56a [doc] correct import for i18n
Laurent Peuch <cortex@worlddomination.be>
parents: 11963
diff changeset
    70
  from cubicweb import _
83d7752af56a [doc] correct import for i18n
Laurent Peuch <cortex@worlddomination.be>
parents: 11963
diff changeset
    71
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    73
  moderators = add_entity('CWGroup', name=u"moderators")
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
This adds the `moderators` user group.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    76
3322
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    77
.. sourcecode:: python
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    78
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    79
  wf = add_workflow(u'blog publication workflow', 'BlogEntry')
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    80
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    81
At first, instanciate a new workflow object with a gentle description
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    82
and the concerned entity types (this one can be a tuple for multiple
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    83
value).
3322
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    84
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    85
.. sourcecode:: python
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    86
3322
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    87
  submitted = wf.add_state(_('submitted'), initial=True)
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    88
  published = wf.add_state(_('published'))
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    89
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    90
This will create two entities of type ``State``, one with name
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    91
'submitted', and the other with name 'published'.
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    92
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    93
``add_state`` expects as first argument the name of the state you want
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    94
to create and an optional argument to say if it is supposed to be the
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
    95
initial state of the entity type.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    96
3322
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    97
.. sourcecode:: python
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    98
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
    99
  wf.add_transition(_('approve_blogentry'), (submitted,), published, ('moderators', 'managers'),)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   100
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   101
This will create an entity of type ``Transition`` with name
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   102
`approve_blogentry` which will be linked to the ``State`` entities
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   103
created before.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   104
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   105
``add_transition`` expects
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   106
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   107
  * as the first argument: the name of the transition
3322
a522f86ab617 [D] book: define a workflow
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 2539
diff changeset
   108
  * then the list of states on which the transition can be triggered,
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   109
  * the target state of the transition,
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   110
  * and the permissions
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   111
    (e.g. a list of user groups who can apply the transition; the user
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   112
    has to belong to at least one of the listed group to perform the action).
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   113
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   114
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   115
.. note::
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
   116
  Do not forget to add the `_()` in front of all states and
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
   117
  transitions names while creating a workflow so that they will be
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
   118
  identified by the i18n catalog scripts.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   119
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   120
In addition to the user groups (one of which the user needs to belong
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   121
to), we could have added a RQL condition.  In this case, the user can
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   122
only perform the action if the two conditions are satisfied.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   123
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   124
If we use an RQL condition on a transition, we can use the following variables:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   125
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3560
diff changeset
   126
* `X`, the entity on which we may pass the transition
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3560
diff changeset
   127
* `U`, the user executing that may pass the transition
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   128
12733
d242a1692907 Add documentation on workflow permission
Noe Gaumont <ngaumont@logilab.fr>
parents: 12732
diff changeset
   129
It's also possible to get a given transition (usefull in migration) from a
d242a1692907 Add documentation on workflow permission
Noe Gaumont <ngaumont@logilab.fr>
parents: 12732
diff changeset
   130
workflow use `transition_by_name(trname)`.
d242a1692907 Add documentation on workflow permission
Noe Gaumont <ngaumont@logilab.fr>
parents: 12732
diff changeset
   131
To update the permission associated to the transition use
d242a1692907 Add documentation on workflow permission
Noe Gaumont <ngaumont@logilab.fr>
parents: 12732
diff changeset
   132
`set_permissions(requiredgroups=(), conditions=(), reset=True)`.
d242a1692907 Add documentation on workflow permission
Noe Gaumont <ngaumont@logilab.fr>
parents: 12732
diff changeset
   133
If `reset` is False, then the new permission are added instead of replacing the
d242a1692907 Add documentation on workflow permission
Noe Gaumont <ngaumont@logilab.fr>
parents: 12732
diff changeset
   134
old one.
d242a1692907 Add documentation on workflow permission
Noe Gaumont <ngaumont@logilab.fr>
parents: 12732
diff changeset
   135
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   136
10495
5bd914ebf3ae [doc] fix warnings/errors in doc build
Julien Cristau <julien.cristau@logilab.fr>
parents: 10491
diff changeset
   137
.. image:: ../../../images/03-transitions-view_en.png
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   138
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   139
You can notice that in the action box of a BlogEntry, the state is now
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   140
listed as well as the possible transitions for the current state
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   141
defined by the workflow.
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   142
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   143
The transitions will only be displayed for users having the right permissions.
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   144
In our example, the transition `approve_blogentry` will only be displayed
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   145
for the users belonging to the group `moderators` or `managers`.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   146
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   147
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   148
Two bits of warning
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   149
~~~~~~~~~~~~~~~~~~~
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   150
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   151
We could perfectly use the administration interface to do these
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   152
operations. It is a convenient thing to do at times (when doing
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   153
development, to quick-check things). But it is not recommended beyond
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   154
that because it is a bit complicated to do it right and it will be
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   155
only local to your instance (or, said a bit differently, such a
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   156
workflow only exists in an instance database). Furthermore, you cannot
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   157
write unit tests against deployed instances, and experience shows it
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   158
is mandatory to have tests for any mildly complicated workflow
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   159
setup.
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   160
3560
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   161
Indeed, if you create the states and transitions through the user
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   162
interface, next time you initialize the database you will have to
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   163
re-create all the workflow entities. The user interface should only be
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   164
a reference for you to view the states and transitions, but is not the
7d76775f965d fixlets on the workflow chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3322
diff changeset
   165
appropriate interface to define your application workflow.
11963
64ecd4d96ac7 [workflow] Utilities for declarative definition of workflows
Christophe de Vienne <christophe@unlish.com>
parents: 10495
diff changeset
   166
64ecd4d96ac7 [workflow] Utilities for declarative definition of workflows
Christophe de Vienne <christophe@unlish.com>
parents: 10495
diff changeset
   167
64ecd4d96ac7 [workflow] Utilities for declarative definition of workflows
Christophe de Vienne <christophe@unlish.com>
parents: 10495
diff changeset
   168
Alternative way to declare workflows
64ecd4d96ac7 [workflow] Utilities for declarative definition of workflows
Christophe de Vienne <christophe@unlish.com>
parents: 10495
diff changeset
   169
------------------------------------
64ecd4d96ac7 [workflow] Utilities for declarative definition of workflows
Christophe de Vienne <christophe@unlish.com>
parents: 10495
diff changeset
   170
64ecd4d96ac7 [workflow] Utilities for declarative definition of workflows
Christophe de Vienne <christophe@unlish.com>
parents: 10495
diff changeset
   171
.. automodule:: cubicweb.wfutils
64ecd4d96ac7 [workflow] Utilities for declarative definition of workflows
Christophe de Vienne <christophe@unlish.com>
parents: 10495
diff changeset
   172
64ecd4d96ac7 [workflow] Utilities for declarative definition of workflows
Christophe de Vienne <christophe@unlish.com>
parents: 10495
diff changeset
   173