author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 22 Jun 2009 14:20:46 +0200 | |
changeset 2129 | fbfab570a276 |
parent 2127 | bc86aa68cc43 |
child 2140 | 1cba3393ba01 |
permissions | -rw-r--r-- |
0 | 1 |
"""core CubicWeb schema necessary for bootstrapping the actual application's schema |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1451
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1451
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
||
2129
fbfab570a276
use RichString
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2127
diff
changeset
|
9 |
from cubicweb.schema import RichString |
0 | 10 |
|
11 |
||
12 |
# not restricted since as "is" is handled as other relations, guests need |
|
13 |
# access to this |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
14 |
class CWEType(MetaEntityType): |
0 | 15 |
"""define an entity type, used to build the application schema""" |
16 |
name = String(required=True, indexed=True, internationalizable=True, |
|
17 |
unique=True, maxsize=64) |
|
1451 | 18 |
description = RichString(internationalizable=True, |
627
36ade1128af7
use RichString wherever possible in the stdlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
19 |
description=_('semantic description of this entity type')) |
0 | 20 |
# necessary to filter using RQL |
21 |
final = Boolean(description=_('automatic')) |
|
22 |
||
23 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
24 |
class CWRType(MetaEntityType): |
0 | 25 |
"""define a relation type, used to build the application schema""" |
26 |
name = String(required=True, indexed=True, internationalizable=True, |
|
27 |
unique=True, maxsize=64) |
|
2129
fbfab570a276
use RichString
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2127
diff
changeset
|
28 |
description = RichString(internationalizable=True, |
fbfab570a276
use RichString
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2127
diff
changeset
|
29 |
description=_('semantic description of this relation type')) |
0 | 30 |
symetric = Boolean(description=_('is this relation equivalent in both direction ?')) |
31 |
inlined = Boolean(description=_('is this relation physically inlined? you should know what you\'re doing if you are changing this!')) |
|
32 |
fulltext_container = String(description=_('if full text content of subject/object entity ' |
|
33 |
'should be added to other side entity (the container).'), |
|
34 |
vocabulary=('', _('subject'), _('object')), |
|
35 |
maxsize=8, default=None) |
|
36 |
final = Boolean(description=_('automatic')) |
|
37 |
||
38 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
39 |
class CWAttribute(MetaEntityType): |
0 | 40 |
"""define a final relation: link a final relation type from a non final |
1451 | 41 |
entity to a final entity type. |
0 | 42 |
|
43 |
used to build the application schema |
|
44 |
""" |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
45 |
relation_type = SubjectRelation('CWRType', cardinality='1*', |
0 | 46 |
constraints=[RQLConstraint('O final TRUE')], |
47 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
48 |
from_entity = SubjectRelation('CWEType', cardinality='1*', |
0 | 49 |
constraints=[RQLConstraint('O final FALSE')], |
50 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
51 |
to_entity = SubjectRelation('CWEType', cardinality='1*', |
0 | 52 |
constraints=[RQLConstraint('O final TRUE')], |
53 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
54 |
constrained_by = SubjectRelation('CWConstraint', cardinality='*1', composite='subject') |
1451 | 55 |
|
0 | 56 |
cardinality = String(maxsize=2, internationalizable=True, |
1979
daf297034197
remove meaningless cards for attributes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
57 |
vocabulary=[_('?1'), _('11')], |
0 | 58 |
description=_('subject/object cardinality')) |
59 |
ordernum = Int(description=('control subject entity\'s relations order'), default=0) |
|
1451 | 60 |
|
0 | 61 |
indexed = Boolean(description=_('create an index for quick search on this attribute')) |
62 |
fulltextindexed = Boolean(description=_('index this attribute\'s value in the plain text index')) |
|
63 |
internationalizable = Boolean(description=_('is this attribute\'s value translatable')) |
|
64 |
defaultval = String(maxsize=256) |
|
1451 | 65 |
|
2129
fbfab570a276
use RichString
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2127
diff
changeset
|
66 |
description = RichString(internationalizable=True, |
fbfab570a276
use RichString
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2127
diff
changeset
|
67 |
description=_('semantic description of this attribute')) |
1451 | 68 |
|
0 | 69 |
|
1451 | 70 |
CARDINALITY_VOCAB = [_('?*'), _('1*'), _('+*'), _('**'), |
71 |
_('?+'), _('1+'), _('++'), _('*+'), |
|
0 | 72 |
_('?1'), _('11'), _('+1'), _('*1'), |
73 |
_('??'), _('1?'), _('+?'), _('*?')] |
|
74 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
75 |
class CWRelation(MetaEntityType): |
0 | 76 |
"""define a non final relation: link a non final relation type from a non |
1451 | 77 |
final entity to a non final entity type. |
0 | 78 |
|
79 |
used to build the application schema |
|
80 |
""" |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
81 |
relation_type = SubjectRelation('CWRType', cardinality='1*', |
0 | 82 |
constraints=[RQLConstraint('O final FALSE')], |
83 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
84 |
from_entity = SubjectRelation('CWEType', cardinality='1*', |
0 | 85 |
constraints=[RQLConstraint('O final FALSE')], |
86 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
87 |
to_entity = SubjectRelation('CWEType', cardinality='1*', |
0 | 88 |
constraints=[RQLConstraint('O final FALSE')], |
89 |
composite='object') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
90 |
constrained_by = SubjectRelation('CWConstraint', cardinality='*1', composite='subject') |
1451 | 91 |
|
0 | 92 |
cardinality = String(maxsize=2, internationalizable=True, |
93 |
vocabulary=CARDINALITY_VOCAB, |
|
94 |
description=_('subject/object cardinality')) |
|
95 |
ordernum = Int(description=_('control subject entity\'s relations order'), |
|
96 |
default=0) |
|
97 |
composite = String(description=_('is the subject/object entity of the relation ' |
|
98 |
'composed of the other ? This implies that when ' |
|
99 |
'the composite is deleted, composants are also ' |
|
100 |
'deleted.'), |
|
101 |
vocabulary=('', _('subject'), _('object')), |
|
102 |
maxsize=8, default=None) |
|
1451 | 103 |
|
2129
fbfab570a276
use RichString
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2127
diff
changeset
|
104 |
description = RichString(internationalizable=True, |
fbfab570a276
use RichString
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2127
diff
changeset
|
105 |
description=_('semantic description of this relation')) |
1451 | 106 |
|
0 | 107 |
|
108 |
# not restricted since it has to be read when checking allowed transitions |
|
109 |
class RQLExpression(MetaEntityType): |
|
110 |
"""define a rql expression used to define permissions""" |
|
111 |
exprtype = String(required=True, vocabulary=['ERQLExpression', 'RRQLExpression']) |
|
112 |
mainvars = String(maxsize=8, |
|
113 |
description=_('name of the main variables which should be ' |
|
114 |
'used in the selection if necessary (comma ' |
|
115 |
'separated)')) |
|
1451 | 116 |
expression = String(required=True, |
0 | 117 |
description=_('restriction part of a rql query. ' |
118 |
'For entity rql expression, X and U are ' |
|
119 |
'predefined respectivly to the current object and to ' |
|
120 |
'the request user. For relation rql expression, ' |
|
121 |
'S, O and U are predefined respectivly to the current ' |
|
122 |
'relation\'subject, object and to ' |
|
123 |
'the request user. ')) |
|
124 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
125 |
read_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='+?', composite='subject', |
0 | 126 |
description=_('rql expression allowing to read entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
127 |
add_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='*?', composite='subject', |
0 | 128 |
description=_('rql expression allowing to add entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
129 |
delete_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='*?', composite='subject', |
0 | 130 |
description=_('rql expression allowing to delete entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
131 |
update_permission = ObjectRelation('CWEType', cardinality='*?', composite='subject', |
0 | 132 |
description=_('rql expression allowing to update entities of this type')) |
1451 | 133 |
|
0 | 134 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
135 |
class CWConstraint(MetaEntityType): |
0 | 136 |
"""define a schema constraint""" |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
137 |
cstrtype = SubjectRelation('CWConstraintType', cardinality='1*') |
0 | 138 |
value = String(description=_('depends on the constraint type')) |
139 |
||
140 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
141 |
class CWConstraintType(MetaEntityType): |
0 | 142 |
"""define a schema constraint type""" |
143 |
name = String(required=True, indexed=True, internationalizable=True, |
|
144 |
unique=True, maxsize=64) |
|
145 |
||
146 |
||
147 |
# not restricted since it has to be read when checking allowed transitions |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
148 |
class CWGroup(MetaEntityType): |
0 | 149 |
"""define a CubicWeb users group""" |
150 |
name = String(required=True, indexed=True, internationalizable=True, |
|
151 |
unique=True, maxsize=64) |
|
152 |
||
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
153 |
read_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='+*', |
0 | 154 |
description=_('groups allowed to read entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
155 |
add_permission = ObjectRelation(('CWEType', 'CWRType'), |
0 | 156 |
description=_('groups allowed to add entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
157 |
delete_permission = ObjectRelation(('CWEType', 'CWRType'), |
0 | 158 |
description=_('groups allowed to delete entities/relations of this type')) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
159 |
update_permission = ObjectRelation('CWEType', |
0 | 160 |
description=_('groups allowed to update entities of this type')) |
1451 | 161 |
|
162 |
||
163 |
||
0 | 164 |
class relation_type(MetaRelationType): |
165 |
"""link a relation definition to its relation type""" |
|
166 |
inlined = True |
|
167 |
class from_entity(MetaRelationType): |
|
168 |
"""link a relation definition to its subject entity type""" |
|
169 |
inlined = True |
|
170 |
class to_entity(MetaRelationType): |
|
171 |
"""link a relation definition to its object entity type""" |
|
172 |
inlined = True |
|
173 |
class constrained_by(MetaRelationType): |
|
174 |
"""constraints applying on this relation""" |
|
1451 | 175 |
|
0 | 176 |
class cstrtype(MetaRelationType): |
177 |
"""constraint factory""" |
|
178 |
inlined = True |
|
179 |
||
180 |
class read_permission(MetaRelationType): |
|
181 |
"""core relation giving to a group the permission to read an entity or |
|
182 |
relation type |
|
183 |
""" |
|
184 |
class add_permission(MetaRelationType): |
|
185 |
"""core relation giving to a group the permission to add an entity or |
|
186 |
relation type |
|
187 |
""" |
|
188 |
class delete_permission(MetaRelationType): |
|
189 |
"""core relation giving to a group the permission to delete an entity or |
|
190 |
relation type |
|
191 |
""" |
|
192 |
class update_permission(MetaRelationType): |
|
193 |
"""core relation giving to a group the permission to update an entity type |
|
194 |
""" |
|
195 |
||
196 |
||
197 |
class is_(MetaRelationType): |
|
198 |
"""core relation indicating the type of an entity |
|
199 |
""" |
|
200 |
name = 'is' |
|
201 |
# don't explicitly set composite here, this is handled anyway |
|
202 |
#composite = 'object' |
|
203 |
permissions = { |
|
204 |
'read': ('managers', 'users', 'guests'), |
|
205 |
'add': (), |
|
206 |
'delete': (), |
|
207 |
} |
|
208 |
cardinality = '1*' |
|
209 |
subject = '**' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
210 |
object = 'CWEType' |
0 | 211 |
|
212 |
class is_instance_of(MetaRelationType): |
|
213 |
"""core relation indicating the types (including specialized types) |
|
214 |
of an entity |
|
215 |
""" |
|
216 |
# don't explicitly set composite here, this is handled anyway |
|
217 |
#composite = 'object' |
|
218 |
permissions = { |
|
219 |
'read': ('managers', 'users', 'guests'), |
|
220 |
'add': (), |
|
221 |
'delete': (), |
|
222 |
} |
|
223 |
cardinality = '+*' |
|
224 |
subject = '**' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
225 |
object = 'CWEType' |
0 | 226 |
|
227 |
class specializes(MetaRelationType): |
|
228 |
name = 'specializes' |
|
229 |
permissions = { |
|
230 |
'read': ('managers', 'users', 'guests'), |
|
231 |
'add': ('managers',), |
|
232 |
'delete': ('managers',), |
|
233 |
} |
|
234 |
cardinality = '?*' |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
235 |
subject = 'CWEType' |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
628
diff
changeset
|
236 |
object = 'CWEType' |