doc/book/en/devrepo/datamodel/definition.rst
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 17 Jun 2010 17:49:58 +0200
branchstable
changeset 5781 a3e60e0fb0f3
parent 5400 b7ab099b128a
child 5953 af48c527aea7
permissions -rw-r--r--
[doc/book/faq] question on security
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4452
5d6dec2c4650 [doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3811
diff changeset
     1
 .. -*- coding: utf-8 -*-
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
Yams *schema*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
-------------
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
     6
The **schema** is the core piece of a *CubicWeb* instance as it
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
     7
defines and handles the data model. It is based on entity types that
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
     8
are either already defined in `Yams`_ and the *CubicWeb* standard
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
     9
library; or more specific types defined in cubes. The schema for a
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    10
cube is defined in a `schema` python module or package.
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    11
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    12
.. _`Yams`: http://www.logilab.org/project/yams
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    13
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    14
Overview
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    15
~~~~~~~~
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    16
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    17
The core idea of the yams schema is not far from the classical
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    18
`Entity-relationship`_ model. But while an E/R model (or `logical
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    19
model`) traditionally has to be manually translated to a lower-level
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    20
data description language (such as the SQL `create table`
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    21
sublanguage), also often described as the `physical model`, no such
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    22
step is required with |yams| and |cubicweb|.
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    23
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    24
.. _`Entity-relationship`: http://en.wikipedia.org/wiki/Entity-relationship_model
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    25
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    26
This is because in addition to high-level, logical |yams| models, one
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    27
uses the |rql| data manipulation language to query, insert, update and
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    28
delete data. |rql| abstracts as much of the underlying SQL database as
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    29
a |yams| schema abstracts from the physical layout. The vagaries of
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    30
SQL are avoided.
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    31
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    32
As a bonus point, such abstraction make it quite comfortable to build
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    33
or use different backends to which |rql| queries apply.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    35
So, as in the E/R formalism, the building blocks are ``entities``
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    36
(:ref:`EntityType`), ``relationships`` (:ref:`RelationType`,
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    37
:ref:`RelationDefinition`) and ``attributes`` (handled like relation
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    38
with |yams|).
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    39
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    40
Let us detail a little the divergences between E/R and |yams|:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    42
* all relationship are binary which means that to represent a
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    43
  non-binary relationship, one has to use an entity,
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    44
* relationships do not support attributes (yet, see:
5349
023dbeb84cc2 [doc/book] fix wrong (https) url
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5319
diff changeset
    45
  http://www.cubicweb.org/ticket/341318), hence the need to reify it
023dbeb84cc2 [doc/book] fix wrong (https) url
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5319
diff changeset
    46
  as an entity if need arises,
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    47
* all entities have an `eid` attribute (an integer) that is its
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    48
  primary key (but it is possible to declare uniqueness on other
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    49
  attributes)
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    50
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    51
Also |yams| supports the notions of:
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: 4430
diff changeset
    52
5400
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    53
* entity inheritance (quite experimental yet, and completely
b7ab099b128a [doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    54
  undocumented),
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    55
* relation type: that is, relationships can be established over a set
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    56
  of couple of entity types (henre the distinction made between
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    57
  `RelationType` and `RelationDefinition` below)
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    58
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    59
Finally |yams| has a few concepts of its own:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    60
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    61
* relationships being oriented and binary, we call the left hand
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    62
  entity type the `subject` and the right hand entity type the
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    63
  `object`
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    64
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    65
.. note::
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: 4430
diff changeset
    66
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    67
   The |yams| schema is available at run time through the .schema
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    68
   attribute of the `vregistry`.  It's an instance of
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    69
   :class:`cubicweb.schema.Schema`, which extends
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    70
   :class:`yams.schema.Schema`.
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: 4430
diff changeset
    71
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    72
.. _EntityType:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    73
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
Entity type
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
~~~~~~~~~~~
5220
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
    76
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
    77
An entity type is an instance of :class:`yams.schema.EntitySchema`. Each entity type has
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
    78
a set of attributes and relations, and some permissions which define who can add, read,
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: 4430
diff changeset
    79
update or delete entities of this type.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    80
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    81
The following built-in types are available: ``String``, ``Int``,
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    82
``Float``, ``Decimal``, ``Boolean``, ``Date``, ``Datetime``, ``Time``,
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    83
``Interval``, ``Byte`` and ``Password``. They can only be used as
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    84
attributes of an other entity type.
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    85
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    86
You can find more base entity types in
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    87
:ref:`pre_defined_entity_types`.
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    88
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    89
.. XXX yams inheritance
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    90
5220
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
    91
.. _RelationType:
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
    92
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    93
Relation type
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    94
~~~~~~~~~~~~~
5220
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
    95
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    96
A relation type is an instance of
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    97
:class:`yams.schema.RelationSchema`. A relation type is simply a
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    98
semantic definition of a kind of relationship that may occur in an
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
    99
application.
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   100
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   101
It may be referenced by zero, one or more relation definitions.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   102
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   103
It is important to choose a good name, at least to avoid conflicts
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   104
with some semantically different relation defined in other cubes
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   105
(since there's only a shared name space for these names).
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   106
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   107
A relation type holds the following properties (which are hence shared
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   108
between all relation definitions of that type):
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   109
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   110
* `inlined`: boolean handling the physical optimization for archiving
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   111
  the relation in the subject entity table, instead of creating a specific
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: 4430
diff changeset
   112
  table for the relation. This applies to relations where cardinality
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: 4430
diff changeset
   113
  of subject->relation->object is 0..1 (`?`) or 1..1 (`1`) for *all* its relation
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: 4430
diff changeset
   114
  definitions.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   115
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   116
* `symmetric`: boolean indicating that the relation is symmetrical, which
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: 4430
diff changeset
   117
  means that `X relation Y` implies `Y relation X`.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   118
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   119
.. _RelationDefinition:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   120
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   121
Relation definition
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   122
~~~~~~~~~~~~~~~~~~~
5220
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   123
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   124
A relation definition is an instance of
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   125
:class:`yams.schema.RelationDefinition`. It is a complete triplet
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: 4430
diff changeset
   126
"<subject entity type> <relation type> <object entity type>".
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   127
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   128
When creating a new instance of that class, the corresponding
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   129
:class:`RelationType` instance is created on the fly if necessary.
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   130
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   131
Properties
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   132
``````````
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   133
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   134
The available properties for relation definitions are enumerated
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   135
here. There are several kind of properties, as some relation
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   136
definitions are actually attribute definitions, and other are not.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   137
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   138
Some properties may be completely optional, other may have a default
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   139
value.
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   140
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   141
Common properties for attributes and relations:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   142
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   143
* `description`: an unicode string describing an attribute or a
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   144
  relation. By default this string will be used in the editing form of
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   145
  the entity, which means that it is supposed to help the end-user and
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   146
  should be flagged by the function `_` to be properly
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   147
  internationalized.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   148
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   149
* `constraints`: a list of conditions/constraints that the relation has to
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   150
  satisfy (c.f. `Constraints`_)
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   151
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   152
* `cardinality`: a two character string specifying the cardinality of
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   153
  the relation. The first character defines the cardinality of the
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   154
  relation on the subject, and the second on the object. When a
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   155
  relation can have multiple subjects or objects, the cardinality
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   156
  applies to all, not on a one-to-one basis (so it must be
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   157
  consistent...). Default value is '**'. The possible values are
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   158
  inspired from regular expression syntax:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   159
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   160
    * `1`: 1..1
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   161
    * `?`: 0..1
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   162
    * `+`: 1..n
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   163
    * `*`: 0..n
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   164
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   165
Attributes properties:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   166
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   167
* `unique`: boolean indicating if the value of the attribute has to be
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   168
  unique or not within all entities of the same type (false by
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   169
  default)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   170
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   171
* `indexed`: boolean indicating if an index needs to be created for
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   172
  this attribute in the database (false by default). This is useful
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   173
  only if you know that you will have to run numerous searches on the
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   174
  value of this attribute.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   175
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   176
* `default`: default value of the attribute. In case of date types, the values
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   177
  which could be used correspond to the RQL keywords `TODAY` and `NOW`.
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   178
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   179
Properties for `String` attributes:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   180
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   181
* `fulltextindexed`: boolean indicating if the attribute is part of
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   182
  the full text index (false by default) (*applicable on the type
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   183
  `Byte` as well*)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   184
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   185
* `internationalizable`: boolean indicating if the value of the
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   186
  attribute is internationalizable (false by default)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   187
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   188
Relation properties:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   189
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   190
* `composite`: string indicating that the subject (composite ==
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   191
  'subject') is composed of the objects of the relations. For the
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   192
  opposite case (when the object is composed of the subjects of the
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   193
  relation), we just set 'object' as value. The composition implies
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   194
  that when the relation is deleted (so when the composite is deleted,
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   195
  at least), the composed are also deleted.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   196
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   197
* `fulltext_container`: string indicating if the value if the full
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   198
  text indexation of the entity on one end of the relation should be
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   199
  used to find the entity on the other end. The possible values are
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   200
  'subject' or 'object'. For instance the use_email relation has that
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   201
  property set to 'subject', since when performing a full text search
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   202
  people want to find the entity using an email address, and not the
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   203
  entity representing the email address.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   204
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   205
Constraints
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   206
```````````
4032
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   207
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   208
By default, the available constraint types are:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   209
4032
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   210
General Constraints
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   211
......................
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   212
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   213
* `SizeConstraint`: allows to specify a minimum and/or maximum size on
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   214
  string (generic case of `maxsize`)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   215
5220
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   216
* `BoundConstraint`: allows to specify a minimum and/or maximum value
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   217
  on numeric types and date
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   218
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   219
.. sourcecode:: python
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   220
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   221
   from yams.constraints import BoundConstraint, TODAY
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   222
   BoundConstraint('<=', TODAY())
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   223
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   224
* `IntervalBoundConstraint`: allows to specify an interval with
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   225
  included values
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   226
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   227
.. sourcecode:: python
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   228
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   229
     class Node(EntityType):
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   230
         latitude = Float(constraints=[IntervalBoundConstraint(-90, +90)])
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   231
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   232
* `UniqueConstraint`: identical to "unique=True"
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   233
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   234
* `StaticVocabularyConstraint`: identical to "vocabulary=(...)"
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   235
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   236
.. XXX Attribute, NOW
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: 4430
diff changeset
   237
4032
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   238
RQL Based Constraints
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   239
......................
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   240
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   241
RQL based constraints may take three arguments. The first one is the ``WHERE``
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   242
clause of a RQL query used by the constraint. The second argument ``mainvars``
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   243
is the ``Any`` clause of the query. By default this include `S` reserved for the
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   244
subject of the relation and `O` for the object. Additional variables could be
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   245
specified using ``mainvars``. The argument expects a single string with all
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   246
variable's name separated by spaces. The last one, ``msg``, is the error message
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   247
displayed when the constraint fails. As RQLVocabularyConstraint never fails the
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   248
third argument is not available.
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   249
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   250
* `RQLConstraint`: allows to specify a RQL query that has to be satisfied
4032
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   251
  by the subject and/or the object of relation. In this query the variables
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   252
  `S` and `O` are reserved for the relation subject and object entities.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   253
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   254
* `RQLVocabularyConstraint`: similar to the previous type of constraint except
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   255
  that it does not express a "strong" constraint, which means it is only used to
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   256
  restrict the values listed in the drop-down menu of editing form, but it does
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   257
  not prevent another entity to be selected.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   258
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   259
* `RQLUniqueConstraint`: allows to the specify a RQL query that ensure that an
4032
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   260
  attribute is unique in a specific context. The Query must **never** return more
c3a018efe7c9 Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3811
diff changeset
   261
  than a single result to be satisfied. In this query the variables `S` is
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   262
  reserved for the relation subject entity. The other variables should be
4040
00e2f1ae625d Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4032
diff changeset
   263
  specified with the second constructor argument (mainvars). This constraints
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   264
  should be used when UniqueConstraint doesn't fit. Here is a simple example.
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   265
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   266
.. sourcecode:: python
4040
00e2f1ae625d Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4032
diff changeset
   267
00e2f1ae625d Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4032
diff changeset
   268
    # Check that in the same Workflow each state's name is unique.  Using
00e2f1ae625d Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4032
diff changeset
   269
    # UniqueConstraint (or unique=True) here would prevent states in different
00e2f1ae625d Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4032
diff changeset
   270
    # workflows to have the same name.
00e2f1ae625d Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4032
diff changeset
   271
00e2f1ae625d Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4032
diff changeset
   272
    # With: State S, Workflow W, String N ; S state_of W, S name N
00e2f1ae625d Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4032
diff changeset
   273
00e2f1ae625d Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4032
diff changeset
   274
    RQLUniqueConstraint('S name N, S state_of WF, Y state_of WF, Y name N',
00e2f1ae625d Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4032
diff changeset
   275
                        mainvars='Y',
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   276
                        msg=_('workflow already has a state of that name'))
4040
00e2f1ae625d Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 4032
diff changeset
   277
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   278
.. XXX note about how to add new constraint
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   279
4936
a4b772a0d801 Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4744
diff changeset
   280
.. _securitymodel:
a4b772a0d801 Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents: 4744
diff changeset
   281
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   282
The security model
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   283
~~~~~~~~~~~~~~~~~~
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   284
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   285
The security model of `CubicWeb` is based on `Access Control List`.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   286
The main principles are:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   287
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   288
* users and groups of users
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   289
* a user belongs to at least one group of user
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   290
* permissions (read, update, create, delete)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   291
* permissions are assigned to groups (and not to users)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   292
2175
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
   293
For *CubicWeb* in particular:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   294
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   295
* we associate rights at the entities/relations schema level
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   296
* for each entity, we distinguish four kinds of permissions: `read`,
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   297
  `add`, `update` and `delete`
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   298
* for each relation, we distinguish three kinds of permissions: `read`,
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   299
  `add` and `delete` (it is not possible to `modify` a relation)
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   300
* the default groups are: `administrators`, `users` and `guests`
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   301
* by default, users belong to the `users` group
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   302
* there is a virtual group called `owners` to which we
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   303
  can associate only `delete` and `update` permissions
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   304
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   305
  * we can not add users to the `Owners` group, they are
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   306
    implicitly added to it according to the context of the objects
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   307
    they own
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   308
  * the permissions of this group are only checked on `update`/`delete`
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   309
    actions if all the other groups the user belongs to do not provide
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   310
    those permissions
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   311
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: 4430
diff changeset
   312
Setting permissions is done with the attribute `__permissions__` of entities and
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   313
relation types. The value of this attribute is a dictionary where the keys are the access types
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   314
(action), and the values are the authorized groups or expressions.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   315
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   316
For an entity type, the possible actions are `read`, `add`, `update` and
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   317
`delete`.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   318
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   319
For a relation type, the possible actions are `read`, `add`, and `delete`.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   320
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   321
For each access type, a tuple indicates the name of the authorized groups and/or
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   322
one or multiple RQL expressions to satisfy to grant access. The access is
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   323
provided if the user is in one of the listed groups or if one of the RQL condition
4452
5d6dec2c4650 [doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3811
diff changeset
   324
is satisfied.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   325
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   326
The standard user groups
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   327
````````````````````````
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   328
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   329
* `guests`
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   330
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   331
* `users`
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   332
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   333
* `managers`
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   334
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   335
* `owners`: virtual group corresponding to the entity's owner.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   336
  This can only be used for the actions `update` and `delete` of an entity
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   337
  type.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   338
4744
0772d4e29d52 [book] cleanup (deleting/moving) old stuff
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4464
diff changeset
   339
It is also possible to use specific groups if they are defined in the
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   340
precreate script of the cube (``migration/precreate.py``). Defining groups in
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   341
postcreate script or later makes them unavailable for security
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   342
purposes (in this case, an `sync_schema_props_perms` command has to
4744
0772d4e29d52 [book] cleanup (deleting/moving) old stuff
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4464
diff changeset
   343
be issued in a CubicWeb shell).
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   344
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   345
3283
4f53eb3f1331 more doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3144
diff changeset
   346
Use of RQL expression for write permissions
4464
437cc57f7474 fix rest syntax error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4459
diff changeset
   347
```````````````````````````````````````````
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   348
It is possible to define RQL expression to provide update permission
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   349
(`add`, `delete` and `update`) on relation and entity types.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   350
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   351
RQL expression for entity type permission:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   352
3811
3726e921f537 small fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3581
diff changeset
   353
* you have to use the class `ERQLExpression`
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   354
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   355
* the used expression corresponds to the WHERE statement of an RQL query
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   356
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   357
* in this expression, the variables `X` and `U` are pre-defined references
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   358
  respectively on the current entity (on which the action is verified) and
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   359
  on the user who send the request
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   360
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   361
* it is possible to use, in this expression, a special relation
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   362
  "has_<ACTION>_permission" where the subject is the user and the
4452
5d6dec2c4650 [doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3811
diff changeset
   363
  object is any variable, meaning that the user needs to have
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   364
  permission to execute the action <ACTION> on the entities related
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   365
  to this variable
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   366
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   367
For RQL expressions on a relation type, the principles are the same except
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   368
for the following:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   369
3811
3726e921f537 small fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3581
diff changeset
   370
* you have to use the class `RRQLExpression` in the case of a non-final relation
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   371
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   372
* in the expression, the variables `S`, `O` and `U` are pre-defined references
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   373
  to respectively the subject and the object of the current relation (on
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   374
  which the action is being verified) and the user who executed the query
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   375
3811
3726e921f537 small fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3581
diff changeset
   376
* we can also define rights over attributes of an entity (non-final relation),
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   377
  knowing that:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   378
3811
3726e921f537 small fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3581
diff changeset
   379
  - to define RQL expression, we have to use the class `ERQLExpression`
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   380
    in which `X` represents the entity the attribute belongs to
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   381
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   382
  - the permissions `add` and `delete` are equivalent. Only `add`/`read`
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   383
    are actually taken in consideration.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   384
5351
ecf07370e6db [doc/book] a proper note (style)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5349
diff changeset
   385
.. note::
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   386
5351
ecf07370e6db [doc/book] a proper note (style)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5349
diff changeset
   387
  Potentially, the `use of an RQL expression to add an entity or a
ecf07370e6db [doc/book] a proper note (style)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5349
diff changeset
   388
  relation` can cause problems for the user interface, because if the
4452
5d6dec2c4650 [doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3811
diff changeset
   389
  expression uses the entity or the relation to create, then we are
5d6dec2c4650 [doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3811
diff changeset
   390
  not able to verify the permissions before we actually add the entity
5d6dec2c4650 [doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3811
diff changeset
   391
  (please note that this is not a problem for the RQL server at all,
5d6dec2c4650 [doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3811
diff changeset
   392
  because the permissions checks are done after the creation). In such
5d6dec2c4650 [doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3811
diff changeset
   393
  case, the permission check methods (CubicWebEntitySchema.check_perm
5d6dec2c4650 [doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3811
diff changeset
   394
  and has_perm) can indicate that the user is not allowed to create
5351
ecf07370e6db [doc/book] a proper note (style)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5349
diff changeset
   395
  this entity but can obtain the permission.  To compensate this
ecf07370e6db [doc/book] a proper note (style)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5349
diff changeset
   396
  problem, it is usually necessary, for such case, to use an action
ecf07370e6db [doc/book] a proper note (style)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5349
diff changeset
   397
  that reflects the schema permissions but which enables to check
ecf07370e6db [doc/book] a proper note (style)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5349
diff changeset
   398
  properly the permissions so that it would show up if necessary.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   399
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   400
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   401
Use of RQL expression for reading rights
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   402
````````````````````````````````````````
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   403
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   404
The principles are the same but with the following restrictions:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   405
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   406
* we can not use `RRQLExpression` on relation types for reading
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   407
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   408
* special relations "has_<ACTION>_permission" can not be used
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   409
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   410
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   411
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   412
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   413
Defining your schema using yams
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   414
-------------------------------
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   415
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   416
Entity type definition
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   417
~~~~~~~~~~~~~~~~~~~~~~
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   418
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   419
An entity type is defined by a Python class which inherits from
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   420
:class:`yams.buildobjs.EntityType`.  The class definition contains the
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   421
description of attributes and relations for the defined entity type.
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   422
The class name corresponds to the entity type name. It is expected to
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   423
be defined in the module ``mycube.schema``.
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   424
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   425
:Note on schema definition:
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   426
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   427
 The code in ``mycube.schema`` is not meant to be executed. The class
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   428
 EntityType mentioned above is different from the EntitySchema class
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   429
 described in the previous chapter. EntityType is a helper class to
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   430
 make Entity definition easier. Yams will process EntityType classes
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   431
 and create EntitySchema instances from these class definitions. Similar
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   432
 manipulation happen for relations.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   433
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: 4430
diff changeset
   434
When defining a schema using python files, you may use the following shortcuts:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   435
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   436
- `required`: boolean indicating if the attribute is required, ed subject cardinality is '1'
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: 4430
diff changeset
   437
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   438
- `vocabulary`: specify static possible values of an attribute
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: 4430
diff changeset
   439
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   440
- `maxsize`: integer providing the maximum size of a string (no limit by default)
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: 4430
diff changeset
   441
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: 4430
diff changeset
   442
For example:
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: 4430
diff changeset
   443
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: 4430
diff changeset
   444
.. sourcecode:: python
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   445
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   446
  class Person(EntityType):
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   447
    """A person with the properties and the relations necessary for my
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   448
    application"""
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   449
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   450
    last_name = String(required=True, fulltextindexed=True)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   451
    first_name = String(required=True, fulltextindexed=True)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   452
    title = String(vocabulary=('Mr', 'Mrs', 'Miss'))
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   453
    date_of_birth = Date()
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   454
    works_for = SubjectRelation('Company', cardinality='?*')
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   455
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   456
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   457
The entity described above defines three attributes of type String,
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   458
last_name, first_name and title, an attribute of type Date for the date of
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   459
birth and a relation that connects a `Person` to another entity of type
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   460
`Company` through the semantic `works_for`.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   461
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   462
:Naming convention:
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   463
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   464
 Entity class names must start with an uppercase letter. The common
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   465
 usage is to use ``CamelCase`` names.
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   466
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   467
 Attribute and relation names must start with a lowercase letter. The
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   468
 common usage is to use ``underscore_separated_words``. Attribute and
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   469
 relation names starting with a single underscore are permitted, to
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   470
 denote a somewhat "protected" or "private" attribute.
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   471
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   472
 In any case, identifiers starting with "CW" or "cw" are reserved for
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   473
 internal use by the framework.
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   474
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   475
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   476
The name of the Python attribute corresponds to the name of the attribute
2175
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
   477
or the relation in *CubicWeb* application.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   478
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   479
An attribute is defined in the schema as follows::
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   480
4449
0411dca43e05 fix bad rest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4446
diff changeset
   481
    attr_name = attr_type(properties)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   482
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   483
where `attr_type` is one of the type listed above and `properties` is
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   484
a list of the attribute needs to satisfy (see `Properties`_
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   485
for more details).
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   486
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   487
* it is possible to use the attribute `meta` to flag an entity type as a `meta`
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   488
  (e.g. used to describe/categorize other entities)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   489
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   490
.. XXX the paragraph below needs clarification and / or moving out in
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   491
.. another place
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   492
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   493
*Note*: if you end up with an `if` in the definition of your entity, this probably
4430
0b6a069eb29e le patch added_tips a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4040
diff changeset
   494
means that you need two separate entities that implement the `ITree` interface and
0b6a069eb29e le patch added_tips a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4040
diff changeset
   495
get the result from `.children()` which ever entity is concerned.
0b6a069eb29e le patch added_tips a été importé
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4040
diff changeset
   496
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   497
Inheritance
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   498
```````````
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   499
XXX feed me
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   500
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   501
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   502
Definition of relations
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   503
~~~~~~~~~~~~~~~~~~~~~~~
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   504
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   505
XXX add note about defining relation type / definition
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   506
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   507
A relation is defined by a Python class heriting `RelationType`. The name
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   508
of the class corresponds to the name of the type. The class then contains
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   509
a description of the properties of this type of relation, and could as well
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   510
contain a string for the subject and a string for the object. This allows to create
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   511
new definition of associated relations, (so that the class can have the
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   512
definition properties from the relation) for example ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   513
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   514
  class locked_by(RelationType):
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   515
    """relation on all entities indicating that they are locked"""
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   516
    inlined = True
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   517
    cardinality = '?*'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   518
    subject = '*'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   519
    object = 'CWUser'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   520
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   521
If provided, the `subject` and `object` attributes denote the subject
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   522
and object of the various relation definitions related to the relation
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   523
type. Allowed values for these attributes are:
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   524
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   525
* a string corresponding to an entity type
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   526
* a tuple of string corresponding to multiple entity types
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   527
* special string such as follows:
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   528
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   529
  - "**": all types of entities
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   530
  - "*": all types of non-meta entities
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   531
  - "@": all types of meta entities but not system entities (e.g. used for
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   532
    the basic schema description)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   533
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   534
When a relation is not inlined and not symmetrical, and it does not require
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   535
specific permissions, it can be defined using a `SubjectRelation`
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   536
attribute in the EntityType class. The first argument of `SubjectRelation` gives
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   537
the entity type for the object of the relation.
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   538
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   539
:Naming convention:
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   540
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   541
 Although this way of defining relations uses a Python class, the
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   542
 naming convention defined earlier prevails over the PEP8 conventions
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   543
 used in the framework: relation type class names use
5220
42f854b6083d [doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5145
diff changeset
   544
 ``underscore_separated_words``.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   545
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   546
:Historical note:
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   547
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   548
   It has been historically possible to use `ObjectRelation` which
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   549
   defines a relation in the opposite direction. This feature is soon to be
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   550
   deprecated and therefore should not be used in newly written code.
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   551
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   552
:Future deprecation note:
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   553
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   554
  In an even more remote future, it is quite possible that the
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   555
  SubjectRelation shortcut will become deprecated, in favor of the
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   556
  RelationType declaration which offers some advantages in the context
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   557
  of reusable cubes.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   558
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   559
Definition of permissions
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   560
~~~~~~~~~~~~~~~~~~~~~~~~~~
4452
5d6dec2c4650 [doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3811
diff changeset
   561
The entity type `CWPermission` from the standard library
5d6dec2c4650 [doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3811
diff changeset
   562
allows to build very complex and dynamic security architectures. The schema of
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   563
this entity type is as follow:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   564
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: 4430
diff changeset
   565
.. sourcecode:: python
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   566
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: 4430
diff changeset
   567
    class CWPermission(EntityType):
4459
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   568
        """entity type that may be used to construct some advanced security configuration
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   569
        """
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   570
        name = String(required=True, indexed=True, internationalizable=True, maxsize=100)
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   571
        require_group = SubjectRelation('CWGroup', cardinality='+*',
4459
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   572
                                        description=_('groups to which the permission is granted'))
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   573
        require_state = SubjectRelation('State',
3144
a5deac822a13 Bugfix: message was not written in english
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2476
diff changeset
   574
                                        description=_("entity's state in which the permission is applicable"))
4459
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   575
        # can be used on any entity
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   576
        require_permission = ObjectRelation('**', cardinality='*1', composite='subject',
4459
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   577
                                            description=_("link a permission to the entity. This "
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   578
                                                          "permission should be used in the security "
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   579
                                                          "definition of the entity's type to be useful."))
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   580
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   581
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: 4430
diff changeset
   582
Example of configuration:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   583
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: 4430
diff changeset
   584
.. sourcecode:: python
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   585
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   586
    class Version(EntityType):
4459
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   587
        """a version is defining the content of a particular project's release"""
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   588
4459
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   589
        __permissions__ = {'read':   ('managers', 'users', 'guests',),
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   590
                           'update': ('managers', 'logilab', 'owners',),
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   591
                           'delete': ('managers', ),
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   592
                           'add':    ('managers', 'logilab',
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   593
                                       ERQLExpression('X version_of PROJ, U in_group G,'
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   594
                                                 'PROJ require_permission P, P name "add_version",'
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   595
                                                 'P require_group G'),)}
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   596
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   597
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   598
    class version_of(RelationType):
4459
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   599
        """link a version to its project. A version is necessarily linked to one and only one project.
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   600
        """
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   601
        __permissions__ = {'read':   ('managers', 'users', 'guests',),
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   602
                           'delete': ('managers', ),
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   603
                           'add':    ('managers', 'logilab',
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   604
                                  RRQLExpression('O require_permission P, P name "add_version",'
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   605
                                                 'U in_group G, P require_group G'),)
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   606
                       }
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   607
        inlined = True
f628abfb3a6c backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4449 4452
diff changeset
   608
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   609
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   610
This configuration indicates that an entity `CWPermission` named
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   611
"add_version" can be associated to a project and provides rights to create
5145
bfa4d775219f added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 4936
diff changeset
   612
new versions on this project to specific groups. It is important to notice that:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   613
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   614
* in such case, we have to protect both the entity type "Version" and the relation
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   615
  associating a version to a project ("version_of")
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   616
3283
4f53eb3f1331 more doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3144
diff changeset
   617
* because of the genericity of the entity type `CWPermission`, we have to execute
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   618
  a unification with the groups and/or the states if necessary in the expression
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   619
  ("U in_group G, P require_group G" in the above example)
5319
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   620
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   621
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   622
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   623
Handling schema changes
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   624
~~~~~~~~~~~~~~~~~~~~~~~
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   625
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   626
Also, it should be clear that to properly handle data migration, an
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   627
instance's schema is stored in the database, so the python schema file
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   628
used to defined it is only read when the instance is created or
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   629
upgraded.
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   630
9b1b7020d179 [doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5220
diff changeset
   631
.. XXX complete me