doc/book/en/03-sect-definition-schema.en.txt
author Nicolas Chauvat <nicolas.chauvat@logilab.fr>
Fri, 14 Nov 2008 11:05:32 +0100
changeset 74 9a9fe515934d
child 81 f5886815126b
permissions -rw-r--r--
[doc] reuse the lax book
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
74
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     2
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     3
Entity type definition
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     4
----------------------
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     5
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     6
An entity type is defined by a Python class which inherits `EntityType`. The
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     7
class name correponds to the type name. Then the content of the class contains
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     8
the description of attributes and relations for the defined entity type,
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     9
by example ::
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    10
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    11
  class Personne(EntityType):
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    12
    """A person with the properties and the relations necessarry for my
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    13
    application"""
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    14
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    15
    last_name = String(required=True, fulltextindexed=True)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    16
    first_name = String(required=True, fulltextindexed=True)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    17
    title = String(vocabulary=('M', 'Mme', 'Mlle'))
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    18
    date_of_birth = Date()
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    19
    works_for = SubjectRelation('Company', cardinality='?*')
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    20
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    21
* the name of the Python attribute corresponds to the name of the attribute
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    22
  or the relation in `LAX` application.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    23
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    24
* all built-in types are available : `String`, `Int`, `Float`,
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    25
  `Boolean`, `Date`, `Datetime`, `Time`, `Byte`.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    26
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    27
* each entity has at least the following meta-relations :
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    28
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    29
  - `eid` (`Int`)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    30
  
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    31
  - `creation_date` (`Datetime`)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    32
  
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    33
  - `modification_date` (`Datetime`)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    34
  
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    35
  - `created_by` (`EUser`) (which user created the entity)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    36
  
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    37
  - `owned_by` (`EUser`) (who does the entity belongs to, by default the 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    38
     creator but not necessarry and it could have multiple owners)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    39
     
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    40
  - `is` (`EEType`)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    41
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    42
  
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    43
* it is also possible to define relations of type object by using `ObjectRelation`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    44
  instead of `SubjectRelation`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    45
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    46
* the first argument of `SubjectRelation` and `ObjectRelation` gives respectively
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    47
  the object/subject entity type of the relation. This could be :  
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    48
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    49
  * a string corresponding to an entity type
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    50
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    51
  * a tuple of string correponding to multiple entities types
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    52
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    53
  * special string such as follows :
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    54
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    55
    - "**" : all types of entities
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    56
    - "*" : all types of entities non meta
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    57
    - "@" : all types of meta entities but not system entities (e.g. used for
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    58
      the basis schema description)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    59
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    60
* it is possible to use the attribute `meta` to flag an entity type as a `meta`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    61
  (e.g. used to describe/categorize other entities)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    62
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    63
* optional properties for attributes and relations : 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    64
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    65
  - `description` : string describing an attribute or a relation. By default
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    66
    this string will be used in the editing form of the entity, which means
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    67
    that it is supposed to help the end-user and should be flagged by the
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    68
    function `_` to be properly internationalized.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    69
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    70
  - `constraints` : list of conditions/constraints that the relation needs to
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    71
    satisfy (c.f. `Contraints`_)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    72
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    73
  - `cardinality` : two characters string which specify the cardinality of the
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    74
    relation. The first character defines the cardinality of the relation on
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    75
    the subject, the second on the object of the relation. When a relation
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    76
    has multiple possible subjects or objects, the cardinality applies to all
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    77
    and not on a one to one basis (so it must be consistent...). The possible
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    78
    values are inspired from regular expressions syntax :
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    79
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    80
    * `1`: 1..1
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    81
    * `?`: 0..1
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    82
    * `+`: 1..n
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    83
    * `*`: 0..n
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    84
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    85
  - `meta` : boolean indicating that the relation is a meta-relation (false by
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    86
    default)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    87
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    88
* optionnal properties for attributes : 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    89
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    90
  - `required` : boolean indicating if the attribute is required (false by default)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    91
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    92
  - `unique` : boolean indicating if the value of the attribute has to be unique
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    93
    or not within all entities of the same type (false by default)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    94
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    95
  - `indexed` : boolean indicating if an index needs to be created for this 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    96
    attribute in the database (false by default). This is usefull only if
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    97
    you know that you will have to run numerous searches on the value of this
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    98
    attribute.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    99
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   100
  - `default` : default value of the attribute. In case of date types, the values
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   101
    which could be used correpond to the RQL keywords `TODAY` and `NOW`.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   102
  
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   103
  - `vocabulary` : specify static possible values of an attribute
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   104
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   105
* optionnal properties of type `String` : 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   106
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   107
  - `fulltextindexed` : boolean indicating if the attribute is part of
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   108
    the full text index (false by default) (*applicable on the type `Byte`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   109
    as well*)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   110
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   111
  - `internationalizable` : boolean indicating if the value of the attribute
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   112
    is internationalizable (false by default)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   113
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   114
  - `maxsize` : integer providing the maximum size of the string (no limit by default)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   115
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   116
* optionnal properties for relations : 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   117
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   118
  - `composite` : string indicating that the subject (composite == 'subject')
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   119
    is composed of the objects of the relations. For the opposite case (when
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   120
    the object is composed of the subjects of the relation), we just need
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   121
    to set 'object' as the value. The composition implies that when the relation
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   122
    is deleted (so when the composite is deleted), the composed are also deleted.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   123
    [PAS CLAIR]
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   124
  
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   125
Contraints
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   126
``````````
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   127
By default, the available constraints types are :
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   128
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   129
* `SizeConstraint` : allows to specify a minimum and/or maximum size on
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   130
  string (generic case of `maxsize`)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   131
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   132
* `BoundConstraint` : allows to specify a minimum and/or maximum value on 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   133
  numeric types
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   134
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   135
* `UniqueConstraint` : identical to "unique=True"
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   136
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   137
* `StaticVocabularyConstraint` : identical to "vocabulary=(...)"
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   138
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   139
* `RQLConstraint` : allows to specify a RQL query that needs to be satisfied
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   140
  by the subject and/or the object of the relation. In this query the variables
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   141
  `S` and `O` are reserved for the entities subject and object of the 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   142
  relation.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   143
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   144
* `RQLVocabularyConstraint` : similar to the previous type of constraint except
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   145
  that it does not express a "strong" constraint, which means it is only used to
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   146
  restrict the values listed in the drop-down menu of editing form, but it does
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   147
  not prevent another entity to be selected
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   148
  [PAS CLAIR]
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   149
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   150
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   151
Relation type definition
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   152
------------------------
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   153
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   154
A relation is defined by a Python class heriting `RelationType`. The name
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   155
of the class corresponds to the name of the type. The class then contains
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   156
a description of the properties of this type of relation, as well as a
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   157
string for the subject and a string for the object. This allows to create
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   158
new definition of associated relations, (so that the class can have the 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   159
definition properties from the relation)[PAS CLAIR] by example ::
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   160
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   161
  class locked_by(RelationType):
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   162
    """relation on all entities indicating that they are locked"""
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   163
    inlined = True
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   164
    cardinality = '?*'
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   165
    subject = '*'
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   166
    object = 'EUser'
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   167
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   168
In addition to the permissions, the own properties of the relation types
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   169
(shared also by all definition of relation of this type) are :
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   170
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   171
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   172
* `inlined` : boolean handling the physical optimization for archiving
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   173
  the relation in the subject entity table, instead of creating a specific
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   174
  table for the relation. This applies to the relation when the cardinality
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   175
  of subject->relation->object is 0..1 ('?') or 1..1 ('1')
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   176
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   177
* `symetric` : boolean indication that the relation is symetrical, which
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   178
  means `X relation Y` implies `Y relation X`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   179
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   180
In the case of simultaneous relations definitions, `subject` and `object`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   181
can both be equal to the value of the first argument of `SubjectRelation`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   182
and `ObjectRelation`.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   183
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   184
When a relation is not inlined and not symetrical, and it does not require
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   185
specific permissions, its definition (by using `SubjectRelation` and
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   186
`ObjectRelation`) is all we need.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   187
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   188
Permissions definition
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   189
----------------------
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   190
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   191
Define permissions is set through to the attribute `permissions` of entities and
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   192
relations types. It defines a dictionnary where the keys are the access types
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   193
(action), and the values are the authorized groups or expressions.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   194
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   195
For an entity type, the possible actions are `read`, `add`, `update` and
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   196
`delete`.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   197
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   198
For a relation type, the possible actions are `read`, `add`, and `delete`.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   199
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   200
For each access type, a tuple indicates the name of the authorized groups and/or
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   201
one or multiple RQL expressions to satisfy to grant access. The access is
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   202
provided once the user is in the listed groups or one of the RQL condition is
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   203
satisfied.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   204
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   205
The standard groups are :
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   206
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   207
* `guests`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   208
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   209
* `users`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   210
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   211
* `managers`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   212
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   213
* `owners` : virtual group corresponding to the entity's owner.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   214
  This can only be used for the actions `update` and `delete` of an entity
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   215
  type.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   216
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   217
It is also possible to use specific groups if they are define in the precreate 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   218
of the application (``migration/precreate.py``).
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   219
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   220
Use of RQL expression for writing rights
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   221
````````````````````````````````````````
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   222
It is possible to define RQL expression to provide update permission 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   223
(`add`, `delete` and `update`) on relation and entity types.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   224
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   225
RQL expression for entity type permission :
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   226
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   227
* you have to use the class `ERQLExpression`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   228
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   229
* the used expression corresponds to the WHERE statement of an RQL query
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   230
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   231
* in this expression, the variables X and U are pre-defined references
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   232
  respectively on the current entity (on which the action is verified) and
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   233
  on the user who send the request
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   234
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   235
* it is possible to use, in this expression, a special relation 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   236
  "has_<ACTION>_permission" where the subject is the user and the 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   237
  object is a any variable, meaning that the user needs to have
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   238
  permission to execute the action <ACTION> on the entities related
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   239
  to this variable 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   240
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   241
For RQL expressions on a relation type, the principles are the same except 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   242
for the following :
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   243
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   244
* you have to use the class `RQLExpression` in the case of a non-final relation
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   245
  [WHAT IS A NON FINALE RELATION]
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   246
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   247
* in the expression, the variables S, O and U are pre-defined references
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   248
  to respectively the subject and the object of the current relation (on
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   249
  which the action is being verified) and the user who executed the query
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   250
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   251
* we can also defined rights on attributes of an entity (non-final relation),
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   252
  knowing that : 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   253
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   254
  - to defines RQL expression, we have to use the class `ERQLExpression`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   255
    in which X represents the entity the attribute belongs to
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   256
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   257
  - the permissions `add` and `delete` are equivalent. Only `add`/`read`
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   258
    are actually taken in consideration.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   259
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   260
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   261
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   262
In addition to thatm the entity type `EPermission` from the standard library
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   263
allow to build very complex and dynamic security architecture. The schema of
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   264
this entity type is as follow : ::
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   265
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   266
    class EPermission(MetaEntityType):
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   267
	"""entity type that may be used to construct some advanced security configuration
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   268
	"""
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   269
	name = String(required=True, indexed=True, internationalizable=True, maxsize=100)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   270
	require_group = SubjectRelation('EGroup', cardinality='+*',
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   271
					description=_('groups to which the permission is granted'))
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   272
	require_state = SubjectRelation('State',
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   273
				    description=_("entity'state in which the permission is applyable"))
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   274
	# can be used on any entity
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   275
	require_permission = ObjectRelation('**', cardinality='*1', composite='subject',
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   276
					    description=_("link a permission to the entity. This "
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   277
							  "permission should be used in the security "
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   278
							  "definition of the entity's type to be useful."))
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   279
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   280
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   281
Example of configuration ::
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   282
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   283
    ...
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   284
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   285
    class Version(EntityType):
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   286
	"""a version is defining the content of a particular project's release"""
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   287
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   288
	permissions = {'read':   ('managers', 'users', 'guests',),
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   289
		       'update': ('managers', 'logilab', 'owners',),
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   290
		       'delete': ('managers', ),
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   291
		       'add':    ('managers', 'logilab',
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   292
				  ERQLExpression('X version_of PROJ, U in_group G,'
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   293
						 'PROJ require_permission P, P name "add_version",'
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   294
						 'P require_group G'),)}
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   295
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   296
    ...
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   297
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   298
    class version_of(RelationType):
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   299
	"""link a version to its project. A version is necessarily linked to one and only one project.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   300
	"""
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   301
	permissions = {'read':   ('managers', 'users', 'guests',),
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   302
		       'delete': ('managers', ),
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   303
		       'add':    ('managers', 'logilab',
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   304
				  RRQLExpression('O require_permission P, P name "add_version",'
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   305
						 'U in_group G, P require_group G'),)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   306
		       }
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   307
	inlined = True
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   308
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   309
This configuration assumes/indicates [???] that an entity `EPermission` named
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   310
"add_version" can be associated to a project and provides rights to create
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   311
new versions on this project to specific groups. It is important to notice that :
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   312
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   313
* in such case, we have to protect both the entity type "Version" and the relation
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   314
  associating a version to a project ("version_of")
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   315
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   316
* because of the genricity of the entity type `EPermission`, we have to execute
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   317
  a unification with the groups and/or the states if necessary in the expression
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   318
  ("U in_group G, P require_group G" in the above example)
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   319
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   320
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   321
Use of RQL expression for reading rights
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   322
````````````````````````````````````````
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   323
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   324
The principles are the same but with the following restrictions :
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   325
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   326
* we can not [??] `RRQLExpression` on relation types for reading
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   327
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   328
* special relations "has_<ACTION>_permission" can not be used
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   329
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   330
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   331
Note on the use of RQL expression for `add` permission
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   332
``````````````````````````````````````````````````````
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   333
Potentially, the use of an RQL expression to add an entity or a relation
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   334
can cause problems for the user interface, because if the expression uses
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   335
the entity or the relation to create, then we are not able to verify the 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   336
permissions before we actually add the entity (please note that this is
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   337
not a problem for the RQL server at all, because the permissions checks are
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   338
done after the creation). In such case, the permission checks methods 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   339
(check_perm, has_perm) can indicate that the user is not allowed to create 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   340
this entity but can obtain the permission. 
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   341
To compensate this problem, it is usually necessary, for such case,
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   342
to use an action that reflects the schema permissions but which enables
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   343
to check properly the permissions so that it would show up if necessary.
9a9fe515934d [doc] reuse the lax book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   344
[PAS CLAIR]