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