author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 14 Dec 2016 17:04:29 +0100 | |
branch | 3.24 |
changeset 11893 | b230f4a4010d |
parent 10496 | e95b559a06a2 |
child 12879 | 7347715bf0ee |
permissions | -rw-r--r-- |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
1 |
.. -*- coding: utf-8 -*- |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
2 |
|
5953
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
3 |
.. _datamodel_definition: |
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
4 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
5 |
Yams *schema* |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
6 |
------------- |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
7 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
8 |
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
|
9 |
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
|
10 |
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
|
11 |
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
|
12 |
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
|
13 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
14 |
.. _`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
|
15 |
|
5953
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
16 |
.. _datamodel_overview: |
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
17 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
18 |
Overview |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
19 |
~~~~~~~~ |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
20 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
21 |
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
|
22 |
`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
|
23 |
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
|
24 |
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
|
25 |
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
|
26 |
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
|
27 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
28 |
.. _`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
|
29 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
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
|
34 |
SQL are avoided. |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
35 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
36 |
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
|
37 |
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
|
38 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
39 |
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
|
40 |
(:ref:`EntityType`), ``relationships`` (:ref:`RelationType`, |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
41 |
: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
|
42 |
with |yams|). |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
43 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
44 |
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
|
45 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
46 |
* 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
|
47 |
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
|
48 |
* 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
|
49 |
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
|
50 |
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
|
51 |
* 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
|
52 |
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
|
53 |
attributes) |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
54 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
55 |
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
|
56 |
|
5400
b7ab099b128a
[doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5394
diff
changeset
|
57 |
* entity inheritance (quite experimental yet, and completely |
b7ab099b128a
[doc/book] various content fixes
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5394
diff
changeset
|
58 |
undocumented), |
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
59 |
* 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
|
60 |
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
|
61 |
`RelationType` and `RelationDefinition` below) |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
62 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
63 |
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
|
64 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
65 |
* 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
|
66 |
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
|
67 |
`object` |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
68 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
69 |
.. 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
|
70 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
: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
|
74 |
: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
|
75 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
76 |
.. _EntityType: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
77 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
78 |
Entity type |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
~~~~~~~~~~~ |
5220
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
80 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
81 |
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
|
82 |
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
|
83 |
update or delete entities of this type. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
84 |
|
6342
efd5ba519263
[book] Talk about RichString in 'Yams schema' section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6150
diff
changeset
|
85 |
The following built-in types are available: ``String``, |
10113
e1e8df594d58
[doc] Add BigInt to the list of built-in types
Christophe de Vienne <christophe@unlish.com>
parents:
9981
diff
changeset
|
86 |
``Int``, ``BigInt``, ``Float``, ``Decimal``, ``Boolean``, |
6342
efd5ba519263
[book] Talk about RichString in 'Yams schema' section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6150
diff
changeset
|
87 |
``Date``, ``Datetime``, ``Time``, ``Interval``, ``Byte`` and |
efd5ba519263
[book] Talk about RichString in 'Yams schema' section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6150
diff
changeset
|
88 |
``Password``. They can only be used as attributes of an other entity |
efd5ba519263
[book] Talk about RichString in 'Yams schema' section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6150
diff
changeset
|
89 |
type. |
efd5ba519263
[book] Talk about RichString in 'Yams schema' section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6150
diff
changeset
|
90 |
|
efd5ba519263
[book] Talk about RichString in 'Yams schema' section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6150
diff
changeset
|
91 |
There is also a `RichString` kindof type: |
efd5ba519263
[book] Talk about RichString in 'Yams schema' section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6150
diff
changeset
|
92 |
|
10496
e95b559a06a2
[doc] more fixes of warnings/errors in doc build
David Douard <david.douard@logilab.fr>
parents:
10491
diff
changeset
|
93 |
.. autofunction:: yams.buildobjs.RichString |
6342
efd5ba519263
[book] Talk about RichString in 'Yams schema' section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6150
diff
changeset
|
94 |
|
10093
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
95 |
The ``__unique_together__`` class attribute is a list of tuples of names of |
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
96 |
attributes or inlined relations. For each tuple, CubicWeb ensures the unicity |
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
97 |
of the combination. For example: |
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
98 |
|
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
99 |
.. sourcecode:: python |
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
100 |
|
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
101 |
class State(EntityType): |
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
102 |
__unique_together__ = [('name', 'state_of')] |
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
103 |
|
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
104 |
name = String(required=True) |
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
105 |
state_of = SubjectRelation('Workflow', cardinality='1*', |
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
106 |
composite='object', inlined=True) |
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
107 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
108 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
109 |
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
|
110 |
:ref:`pre_defined_entity_types`. |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
111 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
112 |
.. XXX yams inheritance |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
113 |
|
5220
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
114 |
.. _RelationType: |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
115 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
116 |
Relation type |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
117 |
~~~~~~~~~~~~~ |
5220
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
118 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
119 |
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
|
120 |
: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
|
121 |
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
|
122 |
application. |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
123 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
124 |
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
|
125 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
126 |
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
|
127 |
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
|
128 |
(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
|
129 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
130 |
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
|
131 |
between all relation definitions of that type): |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
132 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
133 |
* `inlined`: boolean handling the physical optimization for archiving |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
definitions. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
138 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
139 |
* `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
|
140 |
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
|
141 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
142 |
.. _RelationDefinition: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
143 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
144 |
Relation definition |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
145 |
~~~~~~~~~~~~~~~~~~~ |
5220
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
146 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
147 |
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
|
148 |
: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
|
149 |
"<subject entity type> <relation type> <object entity type>". |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
150 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
151 |
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
|
152 |
: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
|
153 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
154 |
Properties |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
155 |
`````````` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
156 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
161 |
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
|
162 |
value. |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
163 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
164 |
Common properties for attributes and relations: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
165 |
|
10222
75d6096216d7
[docstrings] fix project-wide English language mistake
Dimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
parents:
10168
diff
changeset
|
166 |
* `description`: a unicode string describing an attribute or a |
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
internationalized. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
171 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
172 |
* `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
|
173 |
satisfy (c.f. `Constraints`_) |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
174 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
175 |
* `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
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
inspired from regular expression syntax: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
182 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
183 |
* `1`: 1..1 |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
184 |
* `?`: 0..1 |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
185 |
* `+`: 1..n |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
186 |
* `*`: 0..n |
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 |
Attributes 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 |
* `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
|
191 |
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
|
192 |
default) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
193 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
194 |
* `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
|
195 |
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
|
196 |
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
|
197 |
value of this attribute. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
198 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
199 |
* `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
|
200 |
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
|
201 |
|
8125
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
202 |
* `metadata`: Is also accepted as an argument of the attribute contructor. It is |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
203 |
not really an attribute property. see `Metadata`_ for details. |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
204 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
205 |
Properties for `String` attributes: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
206 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
207 |
* `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
|
208 |
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
|
209 |
`Byte` as well*) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
210 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
211 |
* `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
|
212 |
attribute is internationalizable (false by default) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
213 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
214 |
Relation properties: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
215 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
216 |
* `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
|
217 |
'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
|
218 |
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
|
219 |
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
|
220 |
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
|
221 |
at least), the composed are also deleted. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
222 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
223 |
* `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
|
224 |
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
|
225 |
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
|
226 |
'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
|
227 |
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
|
228 |
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
|
229 |
entity representing the email address. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
230 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
231 |
Constraints |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
232 |
``````````` |
4032
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
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 |
By default, the available constraint types are: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
235 |
|
4032
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
236 |
General Constraints |
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
237 |
...................... |
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
238 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
239 |
* `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
|
240 |
string (generic case of `maxsize`) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
241 |
|
9255
46f41c3e1443
remove 3.8 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8125
diff
changeset
|
242 |
* `BoundaryConstraint`: allows to specify a minimum and/or maximum value |
5220
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
243 |
on numeric types and date |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
244 |
|
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
245 |
.. sourcecode:: python |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
246 |
|
10281
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
247 |
from yams.constraints import BoundaryConstraint, TODAY, NOW, Attribute |
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
248 |
|
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
249 |
class DatedEntity(EntityType): |
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
250 |
start = Date(constraints=[BoundaryConstraint('>=', TODAY())]) |
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
251 |
end = Date(constraints=[BoundaryConstraint('>=', Attribute('start'))]) |
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
252 |
|
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
253 |
class Before(EntityType); |
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
254 |
last_time = DateTime(constraints=[BoundaryConstraint('<=', NOW())]) |
5220
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
255 |
|
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
256 |
* `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
|
257 |
included values |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
258 |
|
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
259 |
.. sourcecode:: python |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
260 |
|
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
261 |
class Node(EntityType): |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
262 |
latitude = Float(constraints=[IntervalBoundConstraint(-90, +90)]) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
263 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
264 |
* `UniqueConstraint`: identical to "unique=True" |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
265 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
266 |
* `StaticVocabularyConstraint`: identical to "vocabulary=(...)" |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
267 |
|
10281
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
268 |
Constraints can be dependent on a fixed value (90, Date(2015,3,23)) or a variable. |
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
269 |
In this second case, yams can handle : |
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
270 |
|
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
271 |
* `Attribute`: compare to the value of another attribute. |
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
272 |
* `TODAY`: compare to the current Date. |
cc9eb88377f4
[documentation] add note concerning Attribute, TODAY and NOW in yams documentation
Erica Marco <erica.marco@logilab.fr>
parents:
10168
diff
changeset
|
273 |
* `NOW`: compare to the current Datetime. |
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
|
274 |
|
4032
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
275 |
RQL Based Constraints |
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
276 |
...................... |
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
277 |
|
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
287 |
* `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
|
288 |
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
|
289 |
`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
|
290 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
291 |
* `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
|
292 |
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
|
293 |
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
|
294 |
not prevent another entity to be selected. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
295 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
296 |
* `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
|
297 |
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
|
298 |
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
|
299 |
reserved for the relation subject entity. The other variables should be |
10093
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
300 |
specified with the second constructor argument (mainvars). This constraint type |
516a44ae2cc9
[book] document __unique_together__, remove bad RQLUniqueConstraint example
Julien Cristau <julien.cristau@logilab.fr>
parents:
9990
diff
changeset
|
301 |
should be used when __unique_together__ doesn't fit. |
4040
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
302 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
303 |
.. XXX note about how to add new constraint |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
304 |
|
4936
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4744
diff
changeset
|
305 |
.. _securitymodel: |
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4744
diff
changeset
|
306 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
307 |
The security model |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
308 |
~~~~~~~~~~~~~~~~~~ |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
309 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
310 |
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
|
311 |
The main principles are: |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
312 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
313 |
* users and groups of users |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
314 |
* a user belongs to at least one group of user |
9981
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
315 |
* permissions (`read`, `update`, `create`, `delete`) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
316 |
* permissions are assigned to groups (and not to users) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
317 |
|
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
318 |
For *CubicWeb* in particular: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
319 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
320 |
* we associate rights at the entities/relations schema level |
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
321 |
|
6591
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
322 |
* the default groups are: `managers`, `users` and `guests` |
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
323 |
|
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
324 |
* users belong to the `users` group |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
325 |
|
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
326 |
* there is a virtual group called `owners` to which we can associate only |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
327 |
`delete` and `update` permissions |
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
328 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
329 |
* we can not add users to the `owners` group, they are implicitly added to it |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
330 |
according to the context of the objects they own |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
331 |
|
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
332 |
* the permissions of this group are only checked on `update`/`delete` actions |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
333 |
if all the other groups the user belongs to do not provide those permissions |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
334 |
|
9981
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
335 |
Setting permissions is done with the class attribute `__permissions__` |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
336 |
of entity types and relation definitions. The value of this attribute |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
337 |
is a dictionary where the keys are the access types (action), and the |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
338 |
values are the authorized groups or rql expressions. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
339 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
340 |
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
|
341 |
`delete`. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
342 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
343 |
For a relation, the possible actions are `read`, `add`, and `delete`. |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
344 |
|
9395
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9320
diff
changeset
|
345 |
For an attribute, the possible actions are `read`, `add` and `update`, |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9320
diff
changeset
|
346 |
and they are a refinement of an entity type permission. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
347 |
|
9981
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
348 |
.. note:: |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
349 |
|
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
350 |
By default, the permissions of an entity type attributes are |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
351 |
equivalent to the permissions of the entity type itself. |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
352 |
|
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
353 |
It is possible to provide custom attribute permissions which are |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
354 |
stronger than, or are more lenient than the entity type |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
355 |
permissions. |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
356 |
|
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
357 |
In a situation where all attributes were given custom permissions, |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
358 |
the entity type permissions would not be checked, except for the |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
359 |
`delete` action. |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
360 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
361 |
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
|
362 |
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
|
363 |
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
|
364 |
is satisfied. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
365 |
|
6591
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
366 |
Default permissions |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
367 |
``````````````````` |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
368 |
|
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
369 |
The default permissions for ``EntityType`` are: |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
370 |
|
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
371 |
.. sourcecode:: python |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
372 |
|
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
373 |
__permissions__ = { |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
374 |
'read': ('managers', 'users', 'guests',), |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
375 |
'update': ('managers', 'owners',), |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
376 |
'delete': ('managers', 'owners'), |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
377 |
'add': ('managers', 'users',) |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
378 |
} |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
379 |
|
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
380 |
The default permissions for relations are: |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
381 |
|
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
382 |
.. sourcecode:: python |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
383 |
|
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
384 |
__permissions__ = {'read': ('managers', 'users', 'guests',), |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
385 |
'delete': ('managers', 'users'), |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
386 |
'add': ('managers', 'users',)} |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
387 |
|
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
388 |
The default permissions for attributes are: |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
389 |
|
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
390 |
.. sourcecode:: python |
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
391 |
|
b5ed84c53b3f
[book] complete datamodel definition section with default permissions
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6342
diff
changeset
|
392 |
__permissions__ = {'read': ('managers', 'users', 'guests',), |
9395
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9320
diff
changeset
|
393 |
'add': ('managers', ERQLExpression('U has_add_permission X'), |
96dba2efd16d
[hooks/security] provide attribute "add" permission
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9320
diff
changeset
|
394 |
'update': ('managers', ERQLExpression('U has_update_permission X')),} |
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
395 |
|
9981
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
396 |
.. note:: |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
397 |
|
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
398 |
The default permissions for attributes are not syntactically |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
399 |
equivalent to the default permissions of the entity types, but the |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
400 |
rql expressions work by delegating to the entity type permissions. |
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
401 |
|
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
402 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
403 |
The standard user groups |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
404 |
```````````````````````` |
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 |
* `guests` |
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 |
* `users` |
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 |
* `managers` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
411 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
412 |
* `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
|
413 |
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
|
414 |
type. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
415 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
416 |
It is also possible to use specific groups if they are defined in the precreate |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
417 |
script of the cube (``migration/precreate.py``). Defining groups in postcreate |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
418 |
script or later makes them unavailable for security purposes (in this case, an |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
419 |
`sync_schema_props_perms` command has to be issued in a CubicWeb shell). |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
420 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
421 |
|
3283 | 422 |
Use of RQL expression for write permissions |
4464
437cc57f7474
fix rest syntax error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4459
diff
changeset
|
423 |
``````````````````````````````````````````` |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
424 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
425 |
It is possible to define RQL expression to provide update permission (`add`, |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
426 |
`delete` and `update`) on entity type / relation definitions. An rql expression |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
427 |
is a piece of query (corresponds to the WHERE statement of an RQL query), and the |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
428 |
expression will be considered as satisfied if it returns some results. They can |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
429 |
not be used in `read` permission. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
430 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
431 |
To use RQL expression in entity type permission: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
432 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
433 |
* you have to use the class :class:`~cubicweb.schema.ERQLExpression` |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
434 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
435 |
* in this expression, the variables `X` and `U` are pre-defined references |
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
436 |
respectively on the current entity (on which the action is verified) and on the |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
437 |
user who send the request |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
438 |
|
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
439 |
For RQL expressions on a relation type, the principles are the same except for |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
440 |
the following: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
441 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
442 |
* you have to use the class :class:`~cubicweb.schema.RRQLExpression` instead of |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
443 |
:class:`~cubicweb.schema.ERQLExpression` |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
444 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
445 |
* in the expression, the variables `S`, `O` and `U` are pre-defined references to |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
446 |
respectively the subject and the object of the current relation (on which the |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
447 |
action is being verified) and the user who executed the query |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
448 |
|
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
449 |
To define security for attributes of an entity (non-final relation), you have to |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
450 |
use the class :class:`~cubicweb.schema.ERQLExpression` in which `X` represents |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
451 |
the entity the attribute belongs to. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
452 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
453 |
It is possible to use in those expression a special relation |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
454 |
`has_<ACTION>_permission` where the subject is the user (eg 'U') and the object |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
455 |
is any variable representing an entity (usually 'X' in |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
456 |
:class:`~cubicweb.schema.ERQLExpression`, 'S' or 'O' in |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
457 |
:class:`~cubicweb.schema.RRQLExpression`), meaning that the user needs to have |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
458 |
permission to execute the action <ACTION> on the entities represented by this |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
459 |
variable. It's recommanded to use this feature whenever possible since it |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
460 |
simplify greatly complex security definition and upgrade. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
461 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
462 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
463 |
.. sourcecode:: python |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
464 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
465 |
class my_relation(RelationDefinition): |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
466 |
__permissions__ = {'read': ('managers', 'users'), |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
467 |
'add': ('managers', RRQLExpression('U has_update_permission S')), |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
468 |
'delete': ('managers', RRQLExpression('U has_update_permission S')) |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
469 |
} |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
470 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
471 |
In the above example, user will be allowed to add/delete `my_relation` if he has |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
472 |
the `update` permission on the subject of the relation. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
473 |
|
5351
ecf07370e6db
[doc/book] a proper note (style)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5349
diff
changeset
|
474 |
.. note:: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
475 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
476 |
Potentially, the `use of an RQL expression to add an entity or a relation` can |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
477 |
cause problems for the user interface, because if the expression uses the |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
478 |
entity or the relation to create, we are not able to verify the permissions |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
479 |
before we actually added the entity (please note that this is not a problem for |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
480 |
the RQL server at all, because the permissions checks are done after the |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
481 |
creation). In such case, the permission check methods |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
482 |
(CubicWebEntitySchema.check_perm and has_perm) can indicate that the user is |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
483 |
not allowed to create this entity while it would obtain the permission. To |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
484 |
compensate this problem, it is usually necessary in such case to use an action |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
485 |
that reflects the schema permissions but which check properly the permissions |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
486 |
so that it would show up only if possible. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
487 |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1714
diff
changeset
|
488 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
489 |
Use of RQL expression for reading rights |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
490 |
```````````````````````````````````````` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
491 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
492 |
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
|
493 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
494 |
* you can not use rql expression for the `read` permission of relations and |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
495 |
attributes, |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
496 |
|
6148
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
497 |
* you can not use special `has_<ACTION>_permission` relation in the rql |
59c446a813b5
[book] more about has_<action>_permission and enhance a bit security definition section
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6120
diff
changeset
|
498 |
expression. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
499 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
500 |
|
6120
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
501 |
Important notes about write permissions checking |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
502 |
```````````````````````````````````````````````` |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
503 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
504 |
Write permissions (e.g. 'add', 'update', 'delete') are checked in core hooks. |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
505 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
506 |
When a permission is checked slightly vary according to if it's an entity or |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
507 |
relation, and if the relation is an attribute relation or not). It's important to |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
508 |
understand that since according to when a permission is checked, values returned |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
509 |
by rql expressions may changes, hence the permission being granted or not. |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
510 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
511 |
Here are the current rules: |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
512 |
|
9320
15bd24f9b9e0
[doc/book/security] update description of entity update (Related to #2932033)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9255
diff
changeset
|
513 |
1. permission to add/update entity and its attributes are checked on |
15bd24f9b9e0
[doc/book/security] update description of entity update (Related to #2932033)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9255
diff
changeset
|
514 |
commit |
6120
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
515 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
516 |
2. permission to delete an entity is checked in 'before_delete_entity' hook |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
517 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
518 |
3. permission to add a relation is checked either: |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
519 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
520 |
- in 'before_add_relation' hook if the relation type is in the |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
521 |
`BEFORE_ADD_RELATIONS` set |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
522 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
523 |
- else at commit time if the relation type is in the `ON_COMMIT_ADD_RELATIONS` |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
524 |
set |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
525 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
526 |
- else in 'after_add_relation' hook (the default) |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
527 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
528 |
4. permission to delete a relation is checked in 'before_delete_relation' hook |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
529 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
530 |
Last but not least, remember queries issued from hooks and operation are by |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
531 |
default 'unsafe', eg there are no read or write security checks. |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
532 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
533 |
See :mod:`cubicweb.hooks.security` for more details. |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
534 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
535 |
|
5953
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
536 |
.. _yams_example: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
537 |
|
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
538 |
|
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
539 |
Derived attributes and relations |
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
540 |
-------------------------------- |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
541 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
542 |
.. note:: **TODO** Check organisation of the whole chapter of the documentation |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
543 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
544 |
Cubicweb offers the possibility to *query* data using so called |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
545 |
*computed* relations and attributes. Those are *seen* by RQL requests |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
546 |
as normal attributes and relations but are actually derived from other |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
547 |
attributes and relations. In a first section we'll informally review |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
548 |
two typical use cases. Then we see how to use computed attributes and |
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
549 |
relations in your schema. Last we will consider various significant |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
550 |
aspects of their implementation and the impact on their usage. |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
551 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
552 |
Motivating use cases |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
553 |
~~~~~~~~~~~~~~~~~~~~ |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
554 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
555 |
Computed (or reified) relations |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
556 |
``````````````````````````````` |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
557 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
558 |
It often arises that one must represent a ternary relation, or a |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
559 |
family of relations. For example, in the context of an exhibition |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
560 |
catalog you might want to link all *contributors* to the *work* they |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
561 |
contributed to, but this contribution can be as *illustrator*, |
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
562 |
*author*, *performer*, ... |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
563 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
564 |
The classical way to describe this kind of information within an |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
565 |
entity-relationship schema is to *reify* the relation, that is turn |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
566 |
the relation into a entity. In our example the schema will have a |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
567 |
*Contribution* entity type used to represent the family of the |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
568 |
contribution relations. |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
569 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
570 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
571 |
.. sourcecode:: python |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
572 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
573 |
class ArtWork(EntityType): |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
574 |
name = String() |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
575 |
... |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
576 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
577 |
class Person(EntityType): |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
578 |
name = String() |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
579 |
... |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
580 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
581 |
class Contribution(EntityType): |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
582 |
contributor = SubjectRelation('Person', cardinality='1*', inlined=True) |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
583 |
manifestation = SubjectRelation('ArtWork') |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
584 |
role = SubjectRelation('Role') |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
585 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
586 |
class Role(EntityType): |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
587 |
name = String() |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
588 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
589 |
But then, in order to query the illustrator(s) ``I`` of a work ``W``, |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
590 |
one has to write:: |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
591 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
592 |
Any I, W WHERE C is Contribution, C contributor I, C manifestation W, |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
593 |
C role R, R name 'illustrator' |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
594 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
595 |
whereas we would like to be able to simply write:: |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
596 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
597 |
Any I, W WHERE I illustrator_of W |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
598 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
599 |
This is precisely what the computed relations allow. |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
600 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
601 |
|
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
602 |
Computed (or synthesized) attribute |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
603 |
``````````````````````````````````` |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
604 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
605 |
Assuming a trivial schema for describing employees in companies, one |
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
606 |
can be interested in the total of salaries payed by a company for |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
607 |
all its employees. One has to write:: |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
608 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
609 |
Any C, SUM(SA) GROUPBY S WHERE E works_for C, E salary SA |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
610 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
611 |
whereas it would be most convenient to simply write:: |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
612 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
613 |
Any C, TS WHERE C total_salary TS |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
614 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
615 |
And this is again what computed attributes provide. |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
616 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
617 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
618 |
Using computed attributes and relations |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
619 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
620 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
621 |
Computed (or reified) relations |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
622 |
``````````````````````````````` |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
623 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
624 |
In the above case we would define the *computed relation* |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
625 |
``illustrator_of`` in the schema by: |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
626 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
627 |
.. sourcecode:: python |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
628 |
|
10168
136e6b655cdb
[doc] Fix class name for ComputedRelation; fix code block about computed attributes
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10136
diff
changeset
|
629 |
class illustrator_of(ComputedRelation): |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
630 |
rule = ('C is Contribution, C contributor S, C manifestation O,' |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
631 |
'C role R, R name "illustrator"') |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
632 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
633 |
You will note that: |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
634 |
|
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
635 |
* the ``S`` and ``O`` RQL variables implicitly identify the subject and |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
636 |
object of the defined computed relation, akin to what happens in |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
637 |
RRQLExpression |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
638 |
* the possible subject and object entity types are inferred from the rule; |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
639 |
* computed relation definitions always have empty *add* and *delete* permissions |
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
640 |
* *read* permissions can be defined, permissions from the relations used in the |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
641 |
rewrite rule **are not considered** ; |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
642 |
* nothing else may be defined on the `ComputedRelation` subclass beside |
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
643 |
description, permissions and rule (e.g. no cardinality, composite, etc.,). |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
644 |
`BadSchemaDefinition` is raised on attempt to specify other attributes; |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
645 |
* computed relations can not be used in 'SET' and 'DELETE' rql queries |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
646 |
(`BadQuery` exception raised). |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
647 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
648 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
649 |
NB: The fact that the *add* and *delete* permissions are *empty* even |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
650 |
for managers is expected to make the automatic UI not attempt to edit |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
651 |
them. |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
652 |
|
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
653 |
Computed (or synthesized) attributes |
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
654 |
```````````````````````````````````` |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
655 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
656 |
In the above case we would define the *computed attribute* |
10168
136e6b655cdb
[doc] Fix class name for ComputedRelation; fix code block about computed attributes
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10136
diff
changeset
|
657 |
``total_salary`` on the ``Company`` entity type in the schema by: |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
658 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
659 |
.. sourcecode:: python |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
660 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
661 |
class Company(EntityType): |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
662 |
name = String() |
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
663 |
total_salary = Int(formula='Any SUM(SA) GROUPBY E WHERE P works_for X, E salary SA') |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
664 |
|
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
665 |
* the ``X`` RQL variable implicitly identifies the entity holding the |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
666 |
computed attribute, akin to what happens in ERQLExpression; |
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
667 |
* the type inferred from the formula is checked against the declared type, and |
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
668 |
`BadSchemaDefinition` is raised if they don't match; |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
669 |
* the computed attributes always have empty *update* permissions |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
670 |
* `BadSchemaDefinition` is raised on attempt to set 'update' permissions; |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
671 |
* 'read' permissions can be defined, permissions regarding the formula |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
672 |
**are not considered**; |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
673 |
* other attribute's property (inlined, ...) can be defined as for normal attributes; |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
674 |
* Similarly to computed relation, computed attribute can't be used in 'SET' and |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
675 |
'DELETE' rql queries (`BadQuery` exception raised). |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
676 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
677 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
678 |
API and implementation |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
679 |
~~~~~~~~~~~~~~~~~~~~~~ |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
680 |
|
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
681 |
Representation in the data backend |
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
682 |
`````````````````````````````````` |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
683 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
684 |
Computed relations have no direct representation at the SQL table |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
685 |
level. Instead, each time a query is issued the query is rewritten to |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
686 |
replace the computed relation by its equivalent definition and the |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
687 |
resulting rewritten query is performed in the usual way. |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
688 |
|
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
689 |
On the contrary, computed attributes are represented as a column in the |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
690 |
table for their host entity type, just like normal attributes. Their |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
691 |
value is kept up-to-date with respect to their defintion by a system |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
692 |
of hooks (also called triggers in most RDBMS) which recomputes them |
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
693 |
when the relations and attributes they depend on are modified. |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
694 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
695 |
Yams API |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
696 |
```````` |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
697 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
698 |
When accessing the schema through the *yams API* (not when defining a |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
699 |
schema in a ``schema.py`` file) the computed attributes and relations |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
700 |
are represented as follows: |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
701 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
702 |
relations |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
703 |
The ``yams.RelationSchema`` class has a new ``rule`` attribute |
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
704 |
holding the rule as a string. If this attribute is set all others |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
705 |
must not be set. |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
706 |
attributes |
9973
bbe05c74eb92
[doc] proofreading CWEP002 section
Julien Cristau <julien.cristau@logilab.fr>
parents:
9972
diff
changeset
|
707 |
A new property ``formula`` is added on class |
9972
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
708 |
``yams.RelationDefinitionSchema`` alomng with a new keyword |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
709 |
argument ``formula`` on the initializer. |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
710 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
711 |
Migration |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
712 |
````````` |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
713 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
714 |
The migrations are to be handled as summarized in the array below. |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
715 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
716 |
+------------+---------------------------------------------------+---------------------------------------+ |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
717 |
| | Computed rtype | Computed attribute | |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
718 |
+============+===================================================+=======================================+ |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
719 |
| add | * add_relation_type | * add_attribute | |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
720 |
| | * add_relation_definition should trigger an error | * add_relation_definition | |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
721 |
+------------+---------------------------------------------------+---------------------------------------+ |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
722 |
| modify | * sync_schema_prop_perms: | * sync_schema_prop_perms: | |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
723 |
| | checks the rule is | | |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
724 |
| (rule or | synchronized with the database | - empty the cache, | |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
725 |
| formula) | | - check formula, | |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
726 |
| | | - make sure all the values get | |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
727 |
| | | updated | |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
728 |
+------------+---------------------------------------------------+---------------------------------------+ |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
729 |
| del | * drop_relation_type | * drop_attribute | |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
730 |
| | * drop_relation_definition should trigger an error| * drop_relation_definition | |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
731 |
+------------+---------------------------------------------------+---------------------------------------+ |
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
732 |
|
e210f0e082b0
[CWEP002] document computed relations and attributes
Anthony Truchet <anthony.truchet@logilab.fr>
parents:
9395
diff
changeset
|
733 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
734 |
Defining your schema using yams |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
735 |
------------------------------- |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
736 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
737 |
Entity type definition |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
738 |
~~~~~~~~~~~~~~~~~~~~~~ |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
739 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
740 |
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
|
741 |
: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
|
742 |
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
|
743 |
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
|
744 |
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
|
745 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
746 |
:Note on schema definition: |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
747 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
748 |
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
|
749 |
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
|
750 |
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
|
751 |
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
|
752 |
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
|
753 |
manipulation happen for relations. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
754 |
|
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
|
755 |
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
|
756 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
757 |
- `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
|
758 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
759 |
- `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
|
760 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
761 |
- `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
|
762 |
|
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
|
763 |
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
|
764 |
|
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
|
765 |
.. sourcecode:: python |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
766 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
767 |
class Person(EntityType): |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
768 |
"""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
|
769 |
application""" |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
770 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
771 |
last_name = String(required=True, fulltextindexed=True) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
772 |
first_name = String(required=True, fulltextindexed=True) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
773 |
title = String(vocabulary=('Mr', 'Mrs', 'Miss')) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
774 |
date_of_birth = Date() |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
775 |
works_for = SubjectRelation('Company', cardinality='?*') |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
776 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
777 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
778 |
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
|
779 |
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
|
780 |
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
|
781 |
`Company` through the semantic `works_for`. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
782 |
|
6342
efd5ba519263
[book] Talk about RichString in 'Yams schema' section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6150
diff
changeset
|
783 |
|
efd5ba519263
[book] Talk about RichString in 'Yams schema' section
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
6150
diff
changeset
|
784 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
785 |
:Naming convention: |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
786 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
787 |
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
|
788 |
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
|
789 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
790 |
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
|
791 |
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
|
792 |
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
|
793 |
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
|
794 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
795 |
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
|
796 |
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
|
797 |
|
8125
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
798 |
.. _Metadata: |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
799 |
|
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
800 |
Some attribute using the name of another attribute as prefix are considered |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
801 |
metadata. For example, if an EntityType have both a ``data`` and |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
802 |
``data_format`` attribute, ``data_format`` is view as the ``format`` metadata |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
803 |
of ``data``. Later the :meth:`cw_attr_metadata` method will allow you to fetch |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
804 |
metadata related to an attribute. There are only three valid metadata names: |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
805 |
``format``, ``encoding`` and ``name``. |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
806 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
807 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
808 |
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
|
809 |
or the relation in *CubicWeb* application. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
810 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
811 |
An attribute is defined in the schema as follows:: |
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1714
diff
changeset
|
812 |
|
8125
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
813 |
attr_name = AttrType(*properties, metadata={}) |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
814 |
|
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
815 |
where |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
816 |
|
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
817 |
* `AttrType`: is one of the type listed in EntityType_, |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
818 |
|
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
819 |
* `properties`: is a list of the attribute needs to satisfy (see `Properties`_ |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
820 |
for more details), |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
821 |
|
8125
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
822 |
* `metadata`: is a dictionary of meta attributes related to ``attr_name``. |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
823 |
Dictionary keys are the name of the meta attribute. Dictionary values |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
824 |
attributes objects (like the content of ``AttrType``). For each entry of the |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
825 |
metadata dictionary a ``<attr_name>_<key> = <value>`` attribute is |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
826 |
automaticaly added to the EntityType. see `Metadata`_ section for details |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
827 |
about valid key. |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
828 |
|
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
829 |
|
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
830 |
--- |
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
831 |
|
7070250bf50d
[schema] React to yams improvement of metadata attribute handling.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7797
diff
changeset
|
832 |
While building your schema |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
833 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
834 |
* 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
|
835 |
(e.g. used to describe/categorize other entities) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
836 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
837 |
.. 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
|
838 |
.. another place |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
839 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
840 |
*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
|
841 |
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
|
842 |
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
|
843 |
|
5953
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
844 |
.. Inheritance |
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
845 |
.. ``````````` |
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
846 |
.. XXX feed me |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
847 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
848 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
849 |
Definition of relations |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
850 |
~~~~~~~~~~~~~~~~~~~~~~~ |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
851 |
|
5953
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
852 |
.. XXX add note about defining relation type / definition |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
853 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
854 |
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
|
855 |
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
|
856 |
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
|
857 |
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
|
858 |
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
|
859 |
definition properties from the relation) for example :: |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
860 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
861 |
class locked_by(RelationType): |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
862 |
"""relation on all entities indicating that they are locked""" |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
863 |
inlined = True |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
864 |
cardinality = '?*' |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
865 |
subject = '*' |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
866 |
object = 'CWUser' |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
867 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
868 |
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
|
869 |
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
|
870 |
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
|
871 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
872 |
* 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
|
873 |
* a tuple of string corresponding to multiple entity types |
6150
98642a11aea3
remove some deprecated stuff about relation definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6148
diff
changeset
|
874 |
* the '*' special string, meaning all types of entities |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
875 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
876 |
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
|
877 |
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
|
878 |
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
|
879 |
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
|
880 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
881 |
:Naming convention: |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
882 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
883 |
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
|
884 |
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
|
885 |
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
|
886 |
``underscore_separated_words``. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
887 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
888 |
:Historical note: |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
889 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
890 |
It has been historically possible to use `ObjectRelation` which |
5953
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
891 |
defines a relation in the opposite direction. This feature is |
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
892 |
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
|
893 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
894 |
:Future deprecation note: |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
895 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
896 |
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
|
897 |
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
|
898 |
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
|
899 |
of reusable cubes. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
900 |
|
9981
7099bbd685aa
[hooks/security] allow edition of attributes with permissive permissions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9395
diff
changeset
|
901 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
902 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
903 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
904 |
Handling schema changes |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
905 |
~~~~~~~~~~~~~~~~~~~~~~~ |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
906 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
907 |
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
|
908 |
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
|
909 |
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
|
910 |
upgraded. |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
911 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
912 |
.. XXX complete me |