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