1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 """core CubicWeb schema necessary for bootstrapping the actual instance's schema |
|
19 """ |
|
20 |
|
21 __docformat__ = "restructuredtext en" |
|
22 from cubicweb import _ |
|
23 |
|
24 from yams.buildobjs import (EntityType, RelationType, RelationDefinition, Bytes, |
|
25 SubjectRelation, RichString, String, Boolean, Int) |
|
26 from cubicweb.schema import ( |
|
27 RQLConstraint, |
|
28 PUB_SYSTEM_ENTITY_PERMS, PUB_SYSTEM_REL_PERMS, PUB_SYSTEM_ATTR_PERMS |
|
29 ) |
|
30 |
|
31 # not restricted since as "is" is handled as other relations, guests need |
|
32 # access to this |
|
33 class CWEType(EntityType): |
|
34 """define an entity type, used to build the instance schema""" |
|
35 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
|
36 name = String(required=True, indexed=True, internationalizable=True, |
|
37 unique=True, maxsize=64) |
|
38 description = RichString(internationalizable=True, |
|
39 description=_('semantic description of this entity type')) |
|
40 # necessary to filter using RQL |
|
41 final = Boolean(default=False, description=_('automatic')) |
|
42 |
|
43 |
|
44 class CWRType(EntityType): |
|
45 """define a relation type, used to build the instance schema""" |
|
46 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
|
47 name = String(required=True, indexed=True, internationalizable=True, |
|
48 unique=True, maxsize=64) |
|
49 description = RichString(internationalizable=True, |
|
50 description=_('semantic description of this relation type')) |
|
51 symmetric = Boolean(description=_('is this relation equivalent in both direction ?')) |
|
52 inlined = Boolean(description=_('is this relation physically inlined? you should know what you\'re doing if you are changing this!')) |
|
53 fulltext_container = String(description=_('if full text content of subject/object entity ' |
|
54 'should be added to other side entity (the container).'), |
|
55 vocabulary=('', _('subject'), _('object')), |
|
56 maxsize=8, default=None) |
|
57 final = Boolean(description=_('automatic')) |
|
58 |
|
59 |
|
60 class CWComputedRType(EntityType): |
|
61 """define a virtual relation type, used to build the instance schema""" |
|
62 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
|
63 name = String(required=True, indexed=True, internationalizable=True, |
|
64 unique=True, maxsize=64) |
|
65 description = RichString(internationalizable=True, |
|
66 description=_('semantic description of this relation type')) |
|
67 rule = String(required=True) |
|
68 |
|
69 |
|
70 class CWAttribute(EntityType): |
|
71 """define a final relation: link a final relation type from a non final |
|
72 entity to a final entity type. |
|
73 |
|
74 used to build the instance schema |
|
75 """ |
|
76 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
|
77 relation_type = SubjectRelation('CWRType', cardinality='1*', |
|
78 constraints=[RQLConstraint('O final TRUE')], |
|
79 composite='object') |
|
80 from_entity = SubjectRelation('CWEType', cardinality='1*', |
|
81 constraints=[RQLConstraint('O final FALSE')], |
|
82 composite='object') |
|
83 to_entity = SubjectRelation('CWEType', cardinality='1*', |
|
84 constraints=[RQLConstraint('O final TRUE')], |
|
85 composite='object') |
|
86 constrained_by = SubjectRelation('CWConstraint', cardinality='*1', composite='subject') |
|
87 |
|
88 cardinality = String(maxsize=2, internationalizable=True, |
|
89 vocabulary=[_('?1'), _('11')], |
|
90 description=_('subject/object cardinality')) |
|
91 ordernum = Int(description=('control subject entity\'s relations order'), default=0) |
|
92 |
|
93 formula = String(maxsize=2048) |
|
94 indexed = Boolean(description=_('create an index for quick search on this attribute')) |
|
95 fulltextindexed = Boolean(description=_('index this attribute\'s value in the plain text index')) |
|
96 internationalizable = Boolean(description=_('is this attribute\'s value translatable')) |
|
97 defaultval = Bytes(description=_('default value as gziped pickled python object')) |
|
98 extra_props = Bytes(description=_('additional type specific properties')) |
|
99 |
|
100 description = RichString(internationalizable=True, |
|
101 description=_('semantic description of this attribute')) |
|
102 |
|
103 |
|
104 CARDINALITY_VOCAB = [_('?*'), _('1*'), _('+*'), _('**'), |
|
105 _('?+'), _('1+'), _('++'), _('*+'), |
|
106 _('?1'), _('11'), _('+1'), _('*1'), |
|
107 _('??'), _('1?'), _('+?'), _('*?')] |
|
108 |
|
109 class CWRelation(EntityType): |
|
110 """define a non final relation: link a non final relation type from a non |
|
111 final entity to a non final entity type. |
|
112 |
|
113 used to build the instance schema |
|
114 """ |
|
115 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
|
116 relation_type = SubjectRelation('CWRType', cardinality='1*', |
|
117 constraints=[RQLConstraint('O final FALSE')], |
|
118 composite='object') |
|
119 from_entity = SubjectRelation('CWEType', cardinality='1*', |
|
120 constraints=[RQLConstraint('O final FALSE')], |
|
121 composite='object') |
|
122 to_entity = SubjectRelation('CWEType', cardinality='1*', |
|
123 constraints=[RQLConstraint('O final FALSE')], |
|
124 composite='object') |
|
125 constrained_by = SubjectRelation('CWConstraint', cardinality='*1', composite='subject') |
|
126 |
|
127 cardinality = String(maxsize=2, internationalizable=True, |
|
128 vocabulary=CARDINALITY_VOCAB, |
|
129 description=_('subject/object cardinality')) |
|
130 ordernum = Int(description=_('control subject entity\'s relations order'), |
|
131 default=0) |
|
132 composite = String(description=_('is the subject/object entity of the relation ' |
|
133 'composed of the other ? This implies that when ' |
|
134 'the composite is deleted, composants are also ' |
|
135 'deleted.'), |
|
136 vocabulary=('', _('subject'), _('object')), |
|
137 maxsize=8, default=None) |
|
138 |
|
139 description = RichString(internationalizable=True, |
|
140 description=_('semantic description of this relation')) |
|
141 |
|
142 |
|
143 # not restricted since it has to be read when checking allowed transitions |
|
144 class RQLExpression(EntityType): |
|
145 """define a rql expression used to define permissions""" |
|
146 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
|
147 exprtype = String(required=True, vocabulary=['ERQLExpression', 'RRQLExpression']) |
|
148 mainvars = String(maxsize=8, |
|
149 description=_('name of the main variables which should be ' |
|
150 'used in the selection if necessary (comma ' |
|
151 'separated)')) |
|
152 expression = String(required=True, |
|
153 description=_('restriction part of a rql query. ' |
|
154 'For entity rql expression, X and U are ' |
|
155 'predefined respectivly to the current object and to ' |
|
156 'the request user. For relation rql expression, ' |
|
157 'S, O and U are predefined respectivly to the current ' |
|
158 'relation\'subject, object and to ' |
|
159 'the request user. ')) |
|
160 |
|
161 |
|
162 class CWConstraint(EntityType): |
|
163 """define a schema constraint""" |
|
164 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
|
165 cstrtype = SubjectRelation('CWConstraintType', cardinality='1*') |
|
166 value = String(description=_('depends on the constraint type')) |
|
167 |
|
168 |
|
169 class CWUniqueTogetherConstraint(EntityType): |
|
170 """defines a sql-level multicolumn unique index""" |
|
171 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
|
172 name = String(required=True, unique=True, maxsize=64) |
|
173 constraint_of = SubjectRelation('CWEType', cardinality='1*', composite='object', |
|
174 inlined=True) |
|
175 relations = SubjectRelation('CWRType', cardinality='+*', |
|
176 constraints=[RQLConstraint( |
|
177 'S constraint_of ET, RDEF relation_type O, RDEF from_entity ET, ' |
|
178 'O final TRUE OR (O final FALSE AND O inlined TRUE)')]) |
|
179 |
|
180 |
|
181 class CWConstraintType(EntityType): |
|
182 """define a schema constraint type""" |
|
183 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
|
184 name = String(required=True, indexed=True, internationalizable=True, |
|
185 unique=True, maxsize=64) |
|
186 |
|
187 |
|
188 # not restricted since it has to be read when checking allowed transitions |
|
189 class CWGroup(EntityType): |
|
190 """define a CubicWeb users group""" |
|
191 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
|
192 name = String(required=True, indexed=True, internationalizable=True, |
|
193 unique=True, maxsize=64) |
|
194 |
|
195 |
|
196 class CWProperty(EntityType): |
|
197 """used for cubicweb configuration. Once a property has been created you |
|
198 can't change the key. |
|
199 """ |
|
200 __permissions__ = { |
|
201 'read': ('managers', 'users', 'guests'), |
|
202 'add': ('managers', 'users',), |
|
203 'update': ('managers', 'owners',), |
|
204 'delete': ('managers', 'owners',), |
|
205 } |
|
206 # key is a reserved word for mysql |
|
207 pkey = String(required=True, internationalizable=True, maxsize=256, |
|
208 description=_('defines what\'s the property is applied for. ' |
|
209 'You must select this first to be able to set ' |
|
210 'value')) |
|
211 value = String(internationalizable=True, maxsize=256) |
|
212 |
|
213 class relation_type(RelationType): |
|
214 """link a relation definition to its relation type""" |
|
215 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
216 inlined = True |
|
217 |
|
218 class from_entity(RelationType): |
|
219 """link a relation definition to its subject entity type""" |
|
220 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
221 inlined = True |
|
222 |
|
223 class to_entity(RelationType): |
|
224 """link a relation definition to its object entity type""" |
|
225 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
226 inlined = True |
|
227 |
|
228 class constrained_by(RelationType): |
|
229 """constraints applying on this relation""" |
|
230 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
231 |
|
232 class cstrtype(RelationType): |
|
233 """constraint factory""" |
|
234 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
235 inlined = True |
|
236 |
|
237 |
|
238 class read_permission_cwgroup(RelationDefinition): |
|
239 """groups allowed to read entities/relations of this type""" |
|
240 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
241 name = 'read_permission' |
|
242 subject = ('CWEType', 'CWAttribute', 'CWRelation', 'CWComputedRType') |
|
243 object = 'CWGroup' |
|
244 cardinality = '**' |
|
245 |
|
246 class add_permission_cwgroup(RelationDefinition): |
|
247 """groups allowed to add entities/relations of this type""" |
|
248 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
249 name = 'add_permission' |
|
250 subject = ('CWEType', 'CWRelation', 'CWAttribute') |
|
251 object = 'CWGroup' |
|
252 cardinality = '**' |
|
253 |
|
254 class delete_permission_cwgroup(RelationDefinition): |
|
255 """groups allowed to delete entities/relations of this type""" |
|
256 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
257 name = 'delete_permission' |
|
258 subject = ('CWEType', 'CWRelation') |
|
259 object = 'CWGroup' |
|
260 cardinality = '**' |
|
261 |
|
262 class update_permission_cwgroup(RelationDefinition): |
|
263 """groups allowed to update entities/relations of this type""" |
|
264 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
265 name = 'update_permission' |
|
266 subject = ('CWEType', 'CWAttribute') |
|
267 object = 'CWGroup' |
|
268 cardinality = '**' |
|
269 |
|
270 class read_permission_rqlexpr(RelationDefinition): |
|
271 """rql expression allowing to read entities/relations of this type""" |
|
272 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
273 name = 'read_permission' |
|
274 subject = ('CWEType', 'CWAttribute', 'CWRelation', 'CWComputedRType') |
|
275 object = 'RQLExpression' |
|
276 cardinality = '*?' |
|
277 composite = 'subject' |
|
278 |
|
279 class add_permission_rqlexpr(RelationDefinition): |
|
280 """rql expression allowing to add entities/relations of this type""" |
|
281 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
282 name = 'add_permission' |
|
283 subject = ('CWEType', 'CWRelation', 'CWAttribute') |
|
284 object = 'RQLExpression' |
|
285 cardinality = '*?' |
|
286 composite = 'subject' |
|
287 |
|
288 class delete_permission_rqlexpr(RelationDefinition): |
|
289 """rql expression allowing to delete entities/relations of this type""" |
|
290 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
291 name = 'delete_permission' |
|
292 subject = ('CWEType', 'CWRelation') |
|
293 object = 'RQLExpression' |
|
294 cardinality = '*?' |
|
295 composite = 'subject' |
|
296 |
|
297 class update_permission_rqlexpr(RelationDefinition): |
|
298 """rql expression allowing to update entities/relations of this type""" |
|
299 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
300 name = 'update_permission' |
|
301 subject = ('CWEType', 'CWAttribute') |
|
302 object = 'RQLExpression' |
|
303 cardinality = '*?' |
|
304 composite = 'subject' |
|
305 |
|
306 |
|
307 class is_(RelationType): |
|
308 """core relation indicating the type of an entity |
|
309 """ |
|
310 name = 'is' |
|
311 # don't explicitly set composite here, this is handled anyway |
|
312 #composite = 'object' |
|
313 __permissions__ = { |
|
314 'read': ('managers', 'users', 'guests'), |
|
315 'add': (), |
|
316 'delete': (), |
|
317 } |
|
318 cardinality = '1*' |
|
319 subject = '*' |
|
320 object = 'CWEType' |
|
321 |
|
322 class is_instance_of(RelationType): |
|
323 """core relation indicating the types (including specialized types) |
|
324 of an entity |
|
325 """ |
|
326 # don't explicitly set composite here, this is handled anyway |
|
327 #composite = 'object' |
|
328 __permissions__ = { |
|
329 'read': ('managers', 'users', 'guests'), |
|
330 'add': (), |
|
331 'delete': (), |
|
332 } |
|
333 cardinality = '+*' |
|
334 subject = '*' |
|
335 object = 'CWEType' |
|
336 |
|
337 class specializes(RelationType): |
|
338 name = 'specializes' |
|
339 __permissions__ = { |
|
340 'read': ('managers', 'users', 'guests'), |
|
341 'add': ('managers',), |
|
342 'delete': ('managers',), |
|
343 } |
|
344 cardinality = '?*' |
|
345 subject = 'CWEType' |
|
346 object = 'CWEType' |
|
347 |
|
348 def post_build_callback(schema): |
|
349 """set attributes permissions for schema/workflow entities""" |
|
350 from cubicweb.schema import SCHEMA_TYPES, WORKFLOW_TYPES, META_RTYPES |
|
351 wftypes = WORKFLOW_TYPES - set(('TrInfo',)) |
|
352 for eschema in schema.entities(): |
|
353 if eschema in SCHEMA_TYPES or eschema in wftypes: |
|
354 for rschema in eschema.subject_relations(): |
|
355 if rschema.final and not rschema in META_RTYPES: |
|
356 rdef = eschema.rdef(rschema) |
|
357 rdef.permissions = PUB_SYSTEM_ATTR_PERMS |
|