author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 25 Aug 2010 19:01:58 +0200 | |
branch | stable |
changeset 6150 | 98642a11aea3 |
parent 6148 | 59c446a813b5 |
child 6342 | efd5ba519263 |
permissions | -rw-r--r-- |
4452
5d6dec2c4650
[doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3811
diff
changeset
|
1 |
.. -*- coding: utf-8 -*- |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
2 |
|
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 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
85 |
The following built-in types are available: ``String``, ``Int``, |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
86 |
``Float``, ``Decimal``, ``Boolean``, ``Date``, ``Datetime``, ``Time``, |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
87 |
``Interval``, ``Byte`` and ``Password``. They can only be used as |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
88 |
attributes of an other entity type. |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
89 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
90 |
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
|
91 |
:ref:`pre_defined_entity_types`. |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
92 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
93 |
.. XXX yams inheritance |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
94 |
|
5220
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
95 |
.. _RelationType: |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
96 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
97 |
Relation type |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
98 |
~~~~~~~~~~~~~ |
5220
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
99 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
100 |
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
|
101 |
: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
|
102 |
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
|
103 |
application. |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
104 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
105 |
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
|
106 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
(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
|
110 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
111 |
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
|
112 |
between all relation definitions of that type): |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
113 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
114 |
* `inlined`: boolean handling the physical optimization for archiving |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
definitions. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
119 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
120 |
* `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
|
121 |
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
|
122 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
123 |
.. _RelationDefinition: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
124 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
125 |
Relation definition |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
126 |
~~~~~~~~~~~~~~~~~~~ |
5220
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
127 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
128 |
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
|
129 |
: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
|
130 |
"<subject entity type> <relation type> <object entity type>". |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
131 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
132 |
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
|
133 |
: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
|
134 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
135 |
Properties |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
136 |
`````````` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
137 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
142 |
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
|
143 |
value. |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
144 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
145 |
Common properties for attributes and relations: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
146 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
147 |
* `description`: an unicode string describing an attribute or a |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
148 |
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
|
149 |
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
|
150 |
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
|
151 |
internationalized. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
152 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
153 |
* `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
|
154 |
satisfy (c.f. `Constraints`_) |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
155 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
156 |
* `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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
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
|
161 |
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
|
162 |
inspired from regular expression syntax: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
163 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
164 |
* `1`: 1..1 |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
165 |
* `?`: 0..1 |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
166 |
* `+`: 1..n |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
167 |
* `*`: 0..n |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
168 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
169 |
Attributes properties: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
170 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
171 |
* `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
|
172 |
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
|
173 |
default) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
174 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
175 |
* `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
|
176 |
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
|
177 |
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
|
178 |
value of this attribute. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
179 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
180 |
* `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
|
181 |
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
|
182 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
183 |
Properties for `String` attributes: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
184 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
185 |
* `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
|
186 |
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
|
187 |
`Byte` as well*) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
188 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
189 |
* `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
|
190 |
attribute is internationalizable (false by default) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
191 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
192 |
Relation properties: |
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 |
* `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
|
195 |
'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
|
196 |
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
|
197 |
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
|
198 |
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
|
199 |
at least), the composed are also deleted. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
200 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
201 |
* `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
|
202 |
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
|
203 |
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
|
204 |
'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
|
205 |
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
|
206 |
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
|
207 |
entity representing the email address. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
208 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
209 |
Constraints |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
210 |
``````````` |
4032
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
211 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
212 |
By default, the available constraint types are: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
213 |
|
4032
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
214 |
General Constraints |
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
215 |
...................... |
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
216 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
217 |
* `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
|
218 |
string (generic case of `maxsize`) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
219 |
|
5220
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
220 |
* `BoundConstraint`: allows to specify a minimum and/or maximum value |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
221 |
on numeric types and date |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
222 |
|
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
223 |
.. sourcecode:: python |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
224 |
|
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
225 |
from yams.constraints import BoundConstraint, TODAY |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
226 |
BoundConstraint('<=', TODAY()) |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
227 |
|
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
228 |
* `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
|
229 |
included values |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
230 |
|
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
231 |
.. sourcecode:: python |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
232 |
|
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
233 |
class Node(EntityType): |
42f854b6083d
[doc/book] complete chapter on hooks & ops
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5145
diff
changeset
|
234 |
latitude = Float(constraints=[IntervalBoundConstraint(-90, +90)]) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
235 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
236 |
* `UniqueConstraint`: identical to "unique=True" |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
237 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
238 |
* `StaticVocabularyConstraint`: identical to "vocabulary=(...)" |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
239 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
240 |
.. XXX Attribute, NOW |
4437
21f2e01fdd6a
update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4430
diff
changeset
|
241 |
|
4032
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
242 |
RQL Based Constraints |
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
243 |
...................... |
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
244 |
|
c3a018efe7c9
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3811
diff
changeset
|
245 |
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
|
246 |
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
|
247 |
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
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
254 |
* `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
|
255 |
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
|
256 |
`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
|
257 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
258 |
* `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
|
259 |
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
|
260 |
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
|
261 |
not prevent another entity to be selected. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
262 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
263 |
* `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
|
264 |
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
|
265 |
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
|
266 |
reserved for the relation subject entity. The other variables should be |
4040
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
267 |
specified with the second constructor argument (mainvars). This constraints |
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
268 |
should be used when UniqueConstraint doesn't fit. Here is a simple example. |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
269 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
270 |
.. sourcecode:: python |
4040
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
271 |
|
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
272 |
# Check that in the same Workflow each state's name is unique. Using |
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
273 |
# UniqueConstraint (or unique=True) here would prevent states in different |
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
274 |
# workflows to have the same name. |
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
275 |
|
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
276 |
# With: State S, Workflow W, String N ; S state_of W, S name N |
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
277 |
|
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
278 |
RQLUniqueConstraint('S name N, S state_of WF, Y state_of WF, Y name N', |
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
279 |
mainvars='Y', |
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
280 |
msg=_('workflow already has a state of that name')) |
4040
00e2f1ae625d
Update generic RQL Based Constraints and RQLUniqueConstraint doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4032
diff
changeset
|
281 |
|
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
282 |
.. XXX note about how to add new constraint |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
283 |
|
4936
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4744
diff
changeset
|
284 |
.. _securitymodel: |
a4b772a0d801
Fixed some of the documentation warnings when building the book with sphinx.
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4744
diff
changeset
|
285 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
286 |
The security model |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
287 |
~~~~~~~~~~~~~~~~~~ |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
288 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
289 |
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
|
290 |
The main principles are: |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
291 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
292 |
* users and groups of users |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
293 |
* a user belongs to at least one group of user |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
294 |
* permissions (read, update, create, delete) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
295 |
* permissions are assigned to groups (and not to users) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
296 |
|
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
297 |
For *CubicWeb* in particular: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
298 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
299 |
* 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
|
300 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
301 |
* the default groups are: `administrators`, `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
|
302 |
|
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
|
303 |
* 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
|
304 |
|
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
|
305 |
* 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
|
306 |
`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
|
307 |
|
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
|
308 |
* 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
|
309 |
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
|
310 |
|
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
|
311 |
* 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
|
312 |
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
|
313 |
|
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
|
314 |
Setting permissions is done with the attribute `__permissions__` of entities and |
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
|
315 |
relation definition. The value of this attribute is a dictionary where the keys |
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
|
316 |
are the access types (action), and the values are the authorized groups or |
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
|
317 |
expressions. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
318 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
319 |
For 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
|
320 |
`delete`. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
321 |
|
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
|
322 |
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
|
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 |
For an attribute, the possible actions are `read`, and `update`. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
325 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
is satisfied. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
330 |
|
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
|
331 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
332 |
The standard user groups |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
333 |
```````````````````````` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
334 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
335 |
* `guests` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
336 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
337 |
* `users` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
338 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
339 |
* `managers` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
340 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
341 |
* `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
|
342 |
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
|
343 |
type. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
344 |
|
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
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
`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
|
349 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
350 |
|
3283 | 351 |
Use of RQL expression for write permissions |
4464
437cc57f7474
fix rest syntax error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4459
diff
changeset
|
352 |
``````````````````````````````````````````` |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
353 |
|
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
|
354 |
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
|
355 |
`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
|
356 |
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
|
357 |
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
|
358 |
not be used in `read` permission. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
359 |
|
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
|
360 |
To use RQL expression in entity type permission: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
361 |
|
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
|
362 |
* 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
|
363 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
364 |
* 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
|
365 |
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
|
366 |
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
|
367 |
|
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
|
368 |
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
|
369 |
the following: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
370 |
|
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
|
371 |
* 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
|
372 |
:class:`~cubicweb.schema.ERQLExpression` |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
373 |
|
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
|
374 |
* 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
|
375 |
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
|
376 |
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
|
377 |
|
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
|
378 |
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
|
379 |
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
|
380 |
the entity the attribute belongs to. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
381 |
|
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
|
382 |
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
|
383 |
`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
|
384 |
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
|
385 |
: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
|
386 |
: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
|
387 |
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
|
388 |
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
|
389 |
simplify greatly complex security definition and upgrade. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
390 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
391 |
|
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
|
392 |
.. sourcecode:: python |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
393 |
|
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
|
394 |
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
|
395 |
__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
|
396 |
'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
|
397 |
'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
|
398 |
} |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
399 |
|
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
|
400 |
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
|
401 |
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
|
402 |
|
5351
ecf07370e6db
[doc/book] a proper note (style)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5349
diff
changeset
|
403 |
.. note:: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
404 |
|
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
|
405 |
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
|
406 |
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
|
407 |
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
|
408 |
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
|
409 |
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
|
410 |
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
|
411 |
(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
|
412 |
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
|
413 |
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
|
414 |
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
|
415 |
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
|
416 |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1714
diff
changeset
|
417 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
418 |
Use of RQL expression for reading rights |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
419 |
```````````````````````````````````````` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
420 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
421 |
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
|
422 |
|
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
|
423 |
* 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
|
424 |
attributes, |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
425 |
|
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
|
426 |
* 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
|
427 |
expression. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
428 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
429 |
|
6120
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
430 |
Important notes about write permissions checking |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
431 |
```````````````````````````````````````````````` |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
432 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
433 |
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
|
434 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
435 |
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
|
436 |
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
|
437 |
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
|
438 |
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
|
439 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
440 |
Here are the current rules: |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
441 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
442 |
1. permission to add/update entity and its attributes are checked: |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
443 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
444 |
- on commit if the entity has been added |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
445 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
446 |
- in an 'after_update_entity' hook if the entity has been updated. If it fails |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
447 |
at this time, it will be retried on commit (hence you get the permission if |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
448 |
you have it just after the modification or *at* commit time) |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
449 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
450 |
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
|
451 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
452 |
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
|
453 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
454 |
- 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
|
455 |
`BEFORE_ADD_RELATIONS` set |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
456 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
457 |
- 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
|
458 |
set |
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
459 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
460 |
- 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
|
461 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
462 |
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
|
463 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
464 |
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
|
465 |
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
|
466 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
467 |
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
|
468 |
|
c000e41316ec
[book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5953
diff
changeset
|
469 |
|
5953
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
470 |
.. _yams_example: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
471 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
472 |
Defining your schema using yams |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
473 |
------------------------------- |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
474 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
475 |
Entity type definition |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
476 |
~~~~~~~~~~~~~~~~~~~~~~ |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
477 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
478 |
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
|
479 |
: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
|
480 |
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
|
481 |
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
|
482 |
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
|
483 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
484 |
:Note on schema definition: |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
485 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
486 |
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
|
487 |
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
|
488 |
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
|
489 |
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
|
490 |
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
|
491 |
manipulation happen for relations. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
492 |
|
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
|
493 |
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
|
494 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
495 |
- `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
|
496 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
497 |
- `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
|
498 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
499 |
- `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
|
500 |
|
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
|
501 |
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
|
502 |
|
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
|
503 |
.. sourcecode:: python |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
504 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
505 |
class Person(EntityType): |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
506 |
"""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
|
507 |
application""" |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
508 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
509 |
last_name = String(required=True, fulltextindexed=True) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
510 |
first_name = String(required=True, fulltextindexed=True) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
511 |
title = String(vocabulary=('Mr', 'Mrs', 'Miss')) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
512 |
date_of_birth = Date() |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
513 |
works_for = SubjectRelation('Company', cardinality='?*') |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
514 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
515 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
516 |
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
|
517 |
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
|
518 |
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
|
519 |
`Company` through the semantic `works_for`. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
520 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
521 |
:Naming convention: |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
522 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
523 |
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
|
524 |
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
|
525 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
526 |
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
|
527 |
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
|
528 |
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
|
529 |
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
|
530 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
531 |
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
|
532 |
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
|
533 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
534 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
535 |
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
|
536 |
or the relation in *CubicWeb* application. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
537 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
538 |
An attribute is defined in the schema as follows:: |
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1714
diff
changeset
|
539 |
|
4449
0411dca43e05
fix bad rest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4446
diff
changeset
|
540 |
attr_name = attr_type(properties) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
541 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
542 |
where `attr_type` is one of the type listed above and `properties` is |
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
543 |
a list of the attribute needs to satisfy (see `Properties`_ |
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1714
diff
changeset
|
544 |
for more details). |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
545 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
546 |
* 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
|
547 |
(e.g. used to describe/categorize other entities) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
548 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
549 |
.. 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
|
550 |
.. another place |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
551 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
552 |
*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
|
553 |
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
|
554 |
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
|
555 |
|
5953
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
556 |
.. Inheritance |
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
557 |
.. ``````````` |
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
558 |
.. XXX feed me |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
559 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
560 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
561 |
Definition of relations |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
562 |
~~~~~~~~~~~~~~~~~~~~~~~ |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
563 |
|
5953
af48c527aea7
[doc/book] fix & enhance rql intro chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5400
diff
changeset
|
564 |
.. XXX add note about defining relation type / definition |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
565 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
566 |
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
|
567 |
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
|
568 |
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
|
569 |
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
|
570 |
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
|
571 |
definition properties from the relation) for example :: |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
572 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
573 |
class locked_by(RelationType): |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
574 |
"""relation on all entities indicating that they are locked""" |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
575 |
inlined = True |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
576 |
cardinality = '?*' |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
577 |
subject = '*' |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
578 |
object = 'CWUser' |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
579 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
580 |
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
|
581 |
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
|
582 |
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
|
583 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
584 |
* 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
|
585 |
* 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
|
586 |
* the '*' special string, meaning all types of entities |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
587 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
588 |
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
|
589 |
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
|
590 |
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
|
591 |
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
|
592 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
593 |
:Naming convention: |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
594 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
595 |
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
|
596 |
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
|
597 |
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
|
598 |
``underscore_separated_words``. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
599 |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
600 |
:Historical note: |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
601 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
602 |
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
|
603 |
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
|
604 |
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
|
605 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
606 |
:Future deprecation note: |
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
607 |
|
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
608 |
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
|
609 |
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
|
610 |
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
|
611 |
of reusable cubes. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
612 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
613 |
Definition of permissions |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
614 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4452
5d6dec2c4650
[doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3811
diff
changeset
|
615 |
The entity type `CWPermission` from the standard library |
5d6dec2c4650
[doc] small fixes on security part
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3811
diff
changeset
|
616 |
allows to build very complex and dynamic security architectures. The schema of |
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
617 |
this entity type is as follow: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
618 |
|
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
|
619 |
.. sourcecode:: python |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
620 |
|
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
|
621 |
class CWPermission(EntityType): |
4459 | 622 |
"""entity type that may be used to construct some advanced security configuration |
623 |
""" |
|
624 |
name = String(required=True, indexed=True, internationalizable=True, maxsize=100) |
|
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
625 |
require_group = SubjectRelation('CWGroup', cardinality='+*', |
4459 | 626 |
description=_('groups to which the permission is granted')) |
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
627 |
require_state = SubjectRelation('State', |
3144
a5deac822a13
Bugfix: message was not written in english
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2476
diff
changeset
|
628 |
description=_("entity's state in which the permission is applicable")) |
4459 | 629 |
# can be used on any entity |
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
630 |
require_permission = ObjectRelation('**', cardinality='*1', composite='subject', |
4459 | 631 |
description=_("link a permission to the entity. This " |
632 |
"permission should be used in the security " |
|
633 |
"definition of the entity's type to be useful.")) |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
634 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
635 |
|
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
|
636 |
Example of configuration: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
637 |
|
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
|
638 |
.. sourcecode:: python |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
639 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
640 |
class Version(EntityType): |
4459 | 641 |
"""a version is defining the content of a particular project's release""" |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
642 |
|
4459 | 643 |
__permissions__ = {'read': ('managers', 'users', 'guests',), |
644 |
'update': ('managers', 'logilab', 'owners',), |
|
645 |
'delete': ('managers', ), |
|
646 |
'add': ('managers', 'logilab', |
|
647 |
ERQLExpression('X version_of PROJ, U in_group G,' |
|
648 |
'PROJ require_permission P, P name "add_version",' |
|
649 |
'P require_group G'),)} |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
650 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
651 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
652 |
class version_of(RelationType): |
4459 | 653 |
"""link a version to its project. A version is necessarily linked to one and only one project. |
654 |
""" |
|
655 |
__permissions__ = {'read': ('managers', 'users', 'guests',), |
|
656 |
'delete': ('managers', ), |
|
657 |
'add': ('managers', 'logilab', |
|
658 |
RRQLExpression('O require_permission P, P name "add_version",' |
|
659 |
'U in_group G, P require_group G'),) |
|
660 |
} |
|
661 |
inlined = True |
|
662 |
||
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
663 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
664 |
This configuration indicates that an entity `CWPermission` named |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
665 |
"add_version" can be associated to a project and provides rights to create |
5145
bfa4d775219f
added information about the naming conventions in schema.py
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
4936
diff
changeset
|
666 |
new versions on this project to specific groups. It is important to notice that: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
667 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
668 |
* in such case, we have to protect both the entity type "Version" and the relation |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
669 |
associating a version to a project ("version_of") |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
670 |
|
3283 | 671 |
* because of the genericity of the entity type `CWPermission`, we have to execute |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
672 |
a unification with the groups and/or the states if necessary in the expression |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
673 |
("U in_group G, P require_group G" in the above example) |
5319
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
674 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
675 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
676 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
677 |
Handling schema changes |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
678 |
~~~~~~~~~~~~~~~~~~~~~~~ |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
679 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
680 |
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
|
681 |
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
|
682 |
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
|
683 |
upgraded. |
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
684 |
|
9b1b7020d179
[doc/book] an introduction to yams, layout tweaks
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5220
diff
changeset
|
685 |
.. XXX complete me |