doc/book/en/B0012-schema-definition.en.txt
author Sandrine Ribeau <sandrine.ribeau@logilab.fr>
Thu, 23 Apr 2009 12:11:58 -0700
changeset 1463 136756fff6fb
parent 1442 db4e2508082b
child 1477 b056a49c16dc
child 1598 8f400d5f6742
child 1679 9751949a9379
permissions -rw-r--r--
[doc] s/usefull/useful/
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     2
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
     3
Entity type definition
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
     4
----------------------
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     5
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
     6
An entity type is defined by a Python class which inherits from `EntityType`.
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
     7
The class definition contains the description of attributes and relations
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
     8
for the defined entity type.
1352
9fae16f3e068 [doc] Explicitely name the module in which we define schema to distinguish it from entities.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1222
diff changeset
     9
The class name corresponds to the entity type name. It is exepected to be
9fae16f3e068 [doc] Explicitely name the module in which we define schema to distinguish it from entities.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1222
diff changeset
    10
defined in the module ``mycube.schema``.
9fae16f3e068 [doc] Explicitely name the module in which we define schema to distinguish it from entities.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1222
diff changeset
    11
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    12
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    13
For example ::
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    14
1159
16a426d214ae use english example names
Emile Anclin <emile.anclin@logilab.fr>
parents: 301
diff changeset
    15
  class Person(EntityType):
301
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 292
diff changeset
    16
    """A person with the properties and the relations necessary for my
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    17
    application"""
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    18
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    19
    last_name = String(required=True, fulltextindexed=True)
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    20
    first_name = String(required=True, fulltextindexed=True)
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    21
    title = String(vocabulary=('Mr', 'Mrs', 'Miss'))
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    22
    date_of_birth = Date()
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    23
    works_for = SubjectRelation('Company', cardinality='?*')
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    24
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    25
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    26
The entity described above defines three attributes of type String,
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    27
last_name, first_name and title, an attribute of type Date for the date of
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    28
birth and a relation that connects a `Person` to another entity of type
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    29
`Company` through the semantic `works_for`.
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    30
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    31
The name of the Python attribute corresponds to the name of the attribute
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    32
or the relation in `CubicWeb` application.
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    33
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    34
Built-in types for attributes
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    35
`````````````````````````````
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    36
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    37
All `CubicWeb` built-in types are available : `String`, `Int`, `Float`,
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    38
`Decimal`, `Boolean`, `Date`, `Datetime`, `Time`, `Interval`, `Byte` 
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    39
and `Password`.
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    40
They are implicitely imported (as well as the special the function "_"
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    41
for translation :ref:`internationalization`).
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    42
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    43
An attribute is defined in the schema as follows::
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    44
    
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    45
    attr_name = attr_type(properties*)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    46
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    47
where `attr_type` is one of the type listed above and `properties` is
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    48
a list of  the attribute needs to statisfy (see :ref:`properties`
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    49
for more details). 
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    50
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    51
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    52
Meta-data
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    53
`````````
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    54
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    55
Each entity type has at least the following meta-relations :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    56
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    57
  - `eid` (`Int`)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    58
  
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    59
  - `creation_date` (`Datetime`)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    60
  
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    61
  - `modification_date` (`Datetime`)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    62
  
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    63
  - `created_by` (`EUser`) (which user created the entity)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    64
  
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    65
  - `owned_by` (`EUser`) (to whom the entity belongs; by default the 
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    66
     creator but not necessary, and it could have multiple owners)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    67
     
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    68
  - `is` (`EEType`) (of which type the entity is)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    69
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    70
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    71
* relations can be defined by using `ObjectRelation` or `SubjectRelation`.
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    72
  The first argument of `SubjectRelation` or `ObjectRelation` gives respectively
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    73
  the object/subject entity type of the relation. This could be :  
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    74
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    75
  * a string corresponding to an entity type
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    76
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    77
  * a tuple of string corresponding to multiple entity types
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    78
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    79
  * special string such as follows :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    80
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    81
    - "**" : all types of entities
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    82
    - "*" : all types of non-meta entities 
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    83
    - "@" : all types of meta entities but not system entities (e.g. used for
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    84
      the basic schema description)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    85
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    86
* it is possible to use the attribute `meta` to flag an entity type as a `meta`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    87
  (e.g. used to describe/categorize other entities)
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    88
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    89
Optionnal properties
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    90
````````````````````
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    91
.. _properties:
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    92
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    93
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    94
* optional properties for attributes and relations : 
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    95
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    96
  - `description` : a string describing an attribute or a relation. By default
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    97
    this string will be used in the editing form of the entity, which means
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    98
    that it is supposed to help the end-user and should be flagged by the
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    99
    function `_` to be properly internationalized.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   100
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   101
  - `constraints` : a list of conditions/constraints that the relation has to
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   102
    satisfy (c.f. `Contraints`_)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   103
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   104
  - `cardinality` : a two character string which specify the cardinality of the
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   105
    relation. The first character defines the cardinality of the relation on
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   106
    the subject, and the second on the object. When a relation can have 
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   107
    multiple subjects or objects, the cardinality applies to all,
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   108
    not on a one-to-one basis (so it must be consistent...). The possible
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   109
    values are inspired from regular expression syntax :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   110
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   111
    * `1`: 1..1
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   112
    * `?`: 0..1
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   113
    * `+`: 1..n
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   114
    * `*`: 0..n
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   115
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   116
  - `meta` : boolean indicating that the relation is a meta-relation (false by
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   117
    default)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   118
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   119
* optional properties for attributes : 
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   120
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   121
  - `required` : boolean indicating if the attribute is required (false by default)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   122
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   123
  - `unique` : boolean indicating if the value of the attribute has to be unique
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   124
    or not within all entities of the same type (false by default)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   125
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   126
  - `indexed` : boolean indicating if an index needs to be created for this 
1463
136756fff6fb [doc] s/usefull/useful/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1442
diff changeset
   127
    attribute in the database (false by default). This is useful only if
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   128
    you know that you will have to run numerous searches on the value of this
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   129
    attribute.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   130
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   131
  - `default` : default value of the attribute. In case of date types, the values
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   132
    which could be used correspond to the RQL keywords `TODAY` and `NOW`.
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   133
  
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   134
  - `vocabulary` : specify static possible values of an attribute
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   135
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   136
* optional properties of type `String` : 
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   137
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   138
  - `fulltextindexed` : boolean indicating if the attribute is part of
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   139
    the full text index (false by default) (*applicable on the type `Byte`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   140
    as well*)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   141
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   142
  - `internationalizable` : boolean indicating if the value of the attribute
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   143
    is internationalizable (false by default)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   144
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   145
  - `maxsize` : integer providing the maximum size of the string (no limit by default)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   146
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   147
* optional properties for relations : 
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   148
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   149
  - `composite` : string indicating that the subject (composite == 'subject')
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   150
    is composed of the objects of the relations. For the opposite case (when
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   151
    the object is composed of the subjects of the relation), we just set 
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   152
    'object' as value. The composition implies that when the relation
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   153
    is deleted (so when the composite is deleted), the composed are also deleted.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   154
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   155
Contraints
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   156
``````````
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   157
By default, the available constraint types are :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   158
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   159
* `SizeConstraint` : allows to specify a minimum and/or maximum size on
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   160
  string (generic case of `maxsize`)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   161
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   162
* `BoundConstraint` : allows to specify a minimum and/or maximum value on 
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   163
  numeric types
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   164
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   165
* `UniqueConstraint` : identical to "unique=True"
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   166
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   167
* `StaticVocabularyConstraint` : identical to "vocabulary=(...)"
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   168
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   169
* `RQLConstraint` : allows to specify a RQL query that has to be satisfied
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   170
  by the subject and/or the object of the relation. In this query the variables
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   171
  `S` and `O` are reserved for the entities subject and object of the 
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   172
  relation.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   173
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   174
* `RQLVocabularyConstraint` : similar to the previous type of constraint except
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   175
  that it does not express a "strong" constraint, which means it is only used to
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   176
  restrict the values listed in the drop-down menu of editing form, but it does
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   177
  not prevent another entity to be selected.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   178
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   179
1205
79d33f7db590 [doc] some more small improvements
Emile Anclin <emile.anclin@logilab.fr>
parents: 1164
diff changeset
   180
Definition of relations
79d33f7db590 [doc] some more small improvements
Emile Anclin <emile.anclin@logilab.fr>
parents: 1164
diff changeset
   181
-----------------------
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   182
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   183
XXX add note about defining relation type / definition
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   184
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   185
A relation is defined by a Python class heriting `RelationType`. The name
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   186
of the class corresponds to the name of the type. The class then contains
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   187
a description of the properties of this type of relation, and could as well 
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   188
contain a string for the subject and a string for the object. This allows to create
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   189
new definition of associated relations, (so that the class can have the 
229
767ff7f5d5a7 [doc] Replace all : s/by example/for example/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 171
diff changeset
   190
definition properties from the relation) for example ::
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   191
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   192
  class locked_by(RelationType):
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   193
    """relation on all entities indicating that they are locked"""
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   194
    inlined = True
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   195
    cardinality = '?*'
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   196
    subject = '*'
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   197
    object = 'EUser'
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   198
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   199
In addition to the permissions, the properties of the relation types
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   200
(shared also by all definition of relation of this type) are :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   201
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   202
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   203
* `inlined` : boolean handling the physical optimization for archiving
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   204
  the relation in the subject entity table, instead of creating a specific
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   205
  table for the relation. This applies to the relation when the cardinality
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   206
  of subject->relation->object is 0..1 (`?`) or 1..1 (`1`)
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   207
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   208
* `symmetric` : boolean indicating that the relation is symmetrical, which
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   209
  means `X relation Y` implies `Y relation X`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   210
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   211
In the case of simultaneous relations definitions, `subject` and `object`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   212
can both be equal to the value of the first argument of `SubjectRelation`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   213
and `ObjectRelation`.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   214
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   215
When a relation is not inlined and not symmetrical, and it does not require
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   216
specific permissions, its definition (by using `SubjectRelation` and
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   217
`ObjectRelation`) is all we need.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   218
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   219
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   220
The security model
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   221
------------------
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   222
128
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   223
The security model of `cubicWeb` is based on `Access Control List`. 
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   224
The main principles are:
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   225
128
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   226
* users and groups of users
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   227
* a user belongs to at least one group of user
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   228
* permissions (read, update, create, delete)
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   229
* permissions are assigned to groups (and not to users)
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   230
128
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   231
For `CubicWeb` in particular:
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   232
128
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   233
* we associate rights at the enttities/relations schema level
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   234
* for each entity, we distinguish four kind of permissions: read,
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   235
  add, update and delete
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   236
* for each relation, we distinguish three king of permissions: read,
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   237
  add and delete (we can not modify a relation)
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   238
* the basic groups are: Administrators, Users and Guests
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   239
* by default, users belongs to the group Users
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   240
* there is a virtual group called `Owners users` to which we
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   241
  can associate only deletion and update permissions
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   242
* we can not add users to the `Owners users` group, they are
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   243
  implicetely added to it according to the context of the objects
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   244
  they own
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   245
* the permissions of this group are only be checked on update/deletion
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   246
  actions if all the other groups the user belongs does not provide
40edb9347b1b [doc] Translation of security model section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   247
  those permissions
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   248
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   249
  
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   250
Permissions definition
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   251
``````````````````````
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   252
1205
79d33f7db590 [doc] some more small improvements
Emile Anclin <emile.anclin@logilab.fr>
parents: 1164
diff changeset
   253
Setting permissions is done with the attribute `permissions` of entities and
1222
0d5035525a23 [doc] spelling : dictionary
Emile Anclin <emile.anclin@logilab.fr>
parents: 1205
diff changeset
   254
relation types. It defines a dictionary where the keys are the access types
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   255
(action), and the values are the authorized groups or expressions.
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   256
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   257
For an entity type, the possible actions are `read`, `add`, `update` and
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   258
`delete`.
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   259
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   260
For a relation type, the possible actions are `read`, `add`, and `delete`.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   261
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   262
For each access type, a tuple indicates the name of the authorized groups and/or
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   263
one or multiple RQL expressions to satisfy to grant access. The access is
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   264
provided once the user is in the listed groups or one of the RQL condition is
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   265
satisfied.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   266
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   267
The standard groups are :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   268
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   269
* `guests`
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   270
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   271
* `users`
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   272
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   273
* `managers`
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   274
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   275
* `owners` : virtual group corresponding to the entity's owner.
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   276
  This can only be used for the actions `update` and `delete` of an entity
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   277
  type.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   278
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   279
It is also possible to use specific groups if they are defined in the precreate 
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   280
of the cube (``migration/precreate.py``).
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   281
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   282
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   283
Use of RQL expression for writing rights
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   284
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   285
It is possible to define RQL expression to provide update permission 
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   286
(`add`, `delete` and `update`) on relation and entity types.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   287
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   288
RQL expression for entity type permission :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   289
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   290
* you have to use the class `ERQLExpression`
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   291
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   292
* the used expression corresponds to the WHERE statement of an RQL query
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   293
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   294
* in this expression, the variables X and U are pre-defined references
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   295
  respectively on the current entity (on which the action is verified) and
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   296
  on the user who send the request
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   297
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   298
* it is possible to use, in this expression, a special relation 
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   299
  "has_<ACTION>_permission" where the subject is the user and the 
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   300
  object is a any variable, meaning that the user needs to have
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   301
  permission to execute the action <ACTION> on the entities related
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   302
  to this variable 
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   303
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   304
For RQL expressions on a relation type, the principles are the same except 
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   305
for the following :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   306
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   307
* you have to use the class `RQLExpression` in the case of a non-final relation
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   308
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   309
* in the expression, the variables S, O and U are pre-defined references
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   310
  to respectively the subject and the object of the current relation (on
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   311
  which the action is being verified) and the user who executed the query
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   312
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   313
* we can also defined rights on attributes of an entity (non-final relation),
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   314
  knowing that : 
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   315
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   316
  - to defines RQL expression, we have to use the class `ERQLExpression`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   317
    in which X represents the entity the attribute belongs to
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   318
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   319
  - the permissions `add` and `delete` are equivalent. Only `add`/`read`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   320
    are actually taken in consideration.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   321
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   322
In addition to that the entity type `EPermission` from the standard library
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   323
allow to build very complex and dynamic security architecture. The schema of
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   324
this entity type is as follow : ::
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   325
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   326
    class EPermission(MetaEntityType):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   327
	"""entity type that may be used to construct some advanced security configuration
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   328
	"""
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   329
	name = String(required=True, indexed=True, internationalizable=True, maxsize=100)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   330
	require_group = SubjectRelation('EGroup', cardinality='+*',
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   331
					description=_('groups to which the permission is granted'))
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   332
	require_state = SubjectRelation('State',
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   333
				    description=_("entity'state in which the permission is applyable"))
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   334
	# can be used on any entity
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   335
	require_permission = ObjectRelation('**', cardinality='*1', composite='subject',
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   336
					    description=_("link a permission to the entity. This "
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   337
							  "permission should be used in the security "
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   338
							  "definition of the entity's type to be useful."))
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   339
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   340
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   341
Example of configuration ::
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   342
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   343
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   344
    ...
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   345
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   346
    class Version(EntityType):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   347
	"""a version is defining the content of a particular project's release"""
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   348
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   349
	permissions = {'read':   ('managers', 'users', 'guests',),
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   350
		       'update': ('managers', 'logilab', 'owners',),
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   351
		       'delete': ('managers', ),
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   352
		       'add':    ('managers', 'logilab',
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   353
				  ERQLExpression('X version_of PROJ, U in_group G,'
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   354
						 'PROJ require_permission P, P name "add_version",'
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   355
						 'P require_group G'),)}
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   356
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   357
    ...
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   358
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   359
    class version_of(RelationType):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   360
	"""link a version to its project. A version is necessarily linked to one and only one project.
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   361
	"""
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   362
	permissions = {'read':   ('managers', 'users', 'guests',),
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   363
		       'delete': ('managers', ),
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   364
		       'add':    ('managers', 'logilab',
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   365
				  RRQLExpression('O require_permission P, P name "add_version",'
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   366
						 'U in_group G, P require_group G'),)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   367
		       }
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   368
	inlined = True
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   369
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   370
This configuration indicates that an entity `EPermission` named
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   371
"add_version" can be associated to a project and provides rights to create
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   372
new versions on this project to specific groups. It is important to notice that :
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   373
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   374
* in such case, we have to protect both the entity type "Version" and the relation
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   375
  associating a version to a project ("version_of")
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   376
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   377
* because of the genricity of the entity type `EPermission`, we have to execute
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   378
  a unification with the groups and/or the states if necessary in the expression
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   379
  ("U in_group G, P require_group G" in the above example)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   380
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   381
Use of RQL expression for reading rights
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   382
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   383
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   384
The principles are the same but with the following restrictions :
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   385
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   386
* we can not use `RRQLExpression` on relation types for reading
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   387
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   388
* special relations "has_<ACTION>_permission" can not be used
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   389
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   390
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   391
Note on the use of RQL expression for `add` permission
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   392
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   393
Potentially, the use of an RQL expression to add an entity or a relation
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   394
can cause problems for the user interface, because if the expression uses
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   395
the entity or the relation to create, then we are not able to verify the 
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   396
permissions before we actually add the entity (please note that this is
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   397
not a problem for the RQL server at all, because the permissions checks are
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   398
done after the creation). In such case, the permission check methods 
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   399
(check_perm, has_perm) can indicate that the user is not allowed to create 
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   400
this entity but can obtain the permission. 
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   401
To compensate this problem, it is usually necessary, for such case,
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   402
to use an action that reflects the schema permissions but which enables
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   403
to check properly the permissions so that it would show up if necessary.
171
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   404
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   405
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   406
Updating your application with your new schema
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   407
``````````````````````````````````````````````
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   408
1205
79d33f7db590 [doc] some more small improvements
Emile Anclin <emile.anclin@logilab.fr>
parents: 1164
diff changeset
   409
If you modified your schema, the update is not automatic; indeed, this is 
79d33f7db590 [doc] some more small improvements
Emile Anclin <emile.anclin@logilab.fr>
parents: 1164
diff changeset
   410
in general not a good idea.
79d33f7db590 [doc] some more small improvements
Emile Anclin <emile.anclin@logilab.fr>
parents: 1164
diff changeset
   411
Instead, you call a shell on your application, which is a 
1164
88834894d2d7 explain cubicweb-ctl shell
Emile Anclin <emile.anclin@logilab.fr>
parents: 1163
diff changeset
   412
an interactive python shell, with an appropriate
88834894d2d7 explain cubicweb-ctl shell
Emile Anclin <emile.anclin@logilab.fr>
parents: 1163
diff changeset
   413
cubicweb environment ::
171
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   414
1159
16a426d214ae use english example names
Emile Anclin <emile.anclin@logilab.fr>
parents: 301
diff changeset
   415
   cubicweb-ctl shell myinstance
171
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   416
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   417
and type ::
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   418
1159
16a426d214ae use english example names
Emile Anclin <emile.anclin@logilab.fr>
parents: 301
diff changeset
   419
   add_entity_type('Person')
171
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   420
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   421
And restart your application!