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