6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 _ = unicode |
9 _ = unicode |
10 |
10 |
11 from yams.buildobjs import (EntityType, RelationType, SubjectRelation, |
11 from yams.buildobjs import (EntityType, RelationType, RelationDefinition, |
12 ObjectRelation, RichString, String, Boolean, Int) |
12 SubjectRelation, RichString, String, Boolean, Int) |
13 from cubicweb.schema import RQLConstraint |
13 from cubicweb.schema import ( |
14 from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS |
14 RQLConstraint, |
|
15 PUB_SYSTEM_ENTITY_PERMS, PUB_SYSTEM_REL_PERMS, PUB_SYSTEM_ATTR_PERMS |
|
16 ) |
15 |
17 |
16 # not restricted since as "is" is handled as other relations, guests need |
18 # not restricted since as "is" is handled as other relations, guests need |
17 # access to this |
19 # access to this |
18 class CWEType(EntityType): |
20 class CWEType(EntityType): |
19 """define an entity type, used to build the instance schema""" |
21 """define an entity type, used to build the instance schema""" |
20 permissions = META_ETYPE_PERMS |
22 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
21 name = String(required=True, indexed=True, internationalizable=True, |
23 name = String(required=True, indexed=True, internationalizable=True, |
22 unique=True, maxsize=64) |
24 unique=True, maxsize=64) |
23 description = RichString(internationalizable=True, |
25 description = RichString(internationalizable=True, |
24 description=_('semantic description of this entity type')) |
26 description=_('semantic description of this entity type')) |
25 # necessary to filter using RQL |
27 # necessary to filter using RQL |
26 final = Boolean(description=_('automatic')) |
28 final = Boolean(description=_('automatic')) |
27 |
29 |
28 |
30 |
29 class CWRType(EntityType): |
31 class CWRType(EntityType): |
30 """define a relation type, used to build the instance schema""" |
32 """define a relation type, used to build the instance schema""" |
31 permissions = META_ETYPE_PERMS |
33 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
32 name = String(required=True, indexed=True, internationalizable=True, |
34 name = String(required=True, indexed=True, internationalizable=True, |
33 unique=True, maxsize=64) |
35 unique=True, maxsize=64) |
34 description = RichString(internationalizable=True, |
36 description = RichString(internationalizable=True, |
35 description=_('semantic description of this relation type')) |
37 description=_('semantic description of this relation type')) |
36 symetric = Boolean(description=_('is this relation equivalent in both direction ?')) |
38 symmetric = Boolean(description=_('is this relation equivalent in both direction ?')) |
37 inlined = Boolean(description=_('is this relation physically inlined? you should know what you\'re doing if you are changing this!')) |
39 inlined = Boolean(description=_('is this relation physically inlined? you should know what you\'re doing if you are changing this!')) |
38 fulltext_container = String(description=_('if full text content of subject/object entity ' |
40 fulltext_container = String(description=_('if full text content of subject/object entity ' |
39 'should be added to other side entity (the container).'), |
41 'should be added to other side entity (the container).'), |
40 vocabulary=('', _('subject'), _('object')), |
42 vocabulary=('', _('subject'), _('object')), |
41 maxsize=8, default=None) |
43 maxsize=8, default=None) |
129 'the request user. For relation rql expression, ' |
131 'the request user. For relation rql expression, ' |
130 'S, O and U are predefined respectivly to the current ' |
132 'S, O and U are predefined respectivly to the current ' |
131 'relation\'subject, object and to ' |
133 'relation\'subject, object and to ' |
132 'the request user. ')) |
134 'the request user. ')) |
133 |
135 |
134 read_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='+?', composite='subject', |
|
135 description=_('rql expression allowing to read entities/relations of this type')) |
|
136 add_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='*?', composite='subject', |
|
137 description=_('rql expression allowing to add entities/relations of this type')) |
|
138 delete_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='*?', composite='subject', |
|
139 description=_('rql expression allowing to delete entities/relations of this type')) |
|
140 update_permission = ObjectRelation('CWEType', cardinality='*?', composite='subject', |
|
141 description=_('rql expression allowing to update entities of this type')) |
|
142 |
|
143 |
136 |
144 class CWConstraint(EntityType): |
137 class CWConstraint(EntityType): |
145 """define a schema constraint""" |
138 """define a schema constraint""" |
146 permissions = META_ETYPE_PERMS |
139 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
147 cstrtype = SubjectRelation('CWConstraintType', cardinality='1*') |
140 cstrtype = SubjectRelation('CWConstraintType', cardinality='1*') |
148 value = String(description=_('depends on the constraint type')) |
141 value = String(description=_('depends on the constraint type')) |
149 |
142 |
150 |
143 |
151 class CWConstraintType(EntityType): |
144 class CWConstraintType(EntityType): |
152 """define a schema constraint type""" |
145 """define a schema constraint type""" |
153 permissions = META_ETYPE_PERMS |
146 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
154 name = String(required=True, indexed=True, internationalizable=True, |
147 name = String(required=True, indexed=True, internationalizable=True, |
155 unique=True, maxsize=64) |
148 unique=True, maxsize=64) |
156 |
149 |
157 |
150 |
158 # not restricted since it has to be read when checking allowed transitions |
151 # not restricted since it has to be read when checking allowed transitions |
159 class CWGroup(EntityType): |
152 class CWGroup(EntityType): |
160 """define a CubicWeb users group""" |
153 """define a CubicWeb users group""" |
161 permissions = META_ETYPE_PERMS |
154 __permissions__ = PUB_SYSTEM_ENTITY_PERMS |
162 name = String(required=True, indexed=True, internationalizable=True, |
155 name = String(required=True, indexed=True, internationalizable=True, |
163 unique=True, maxsize=64) |
156 unique=True, maxsize=64) |
164 |
157 |
165 read_permission = ObjectRelation(('CWEType', 'CWRType'), cardinality='+*', |
158 |
166 description=_('groups allowed to read entities/relations of this type')) |
159 class CWProperty(EntityType): |
167 add_permission = ObjectRelation(('CWEType', 'CWRType'), |
160 """used for cubicweb configuration. Once a property has been created you |
168 description=_('groups allowed to add entities/relations of this type')) |
161 can't change the key. |
169 delete_permission = ObjectRelation(('CWEType', 'CWRType'), |
162 """ |
170 description=_('groups allowed to delete entities/relations of this type')) |
163 __permissions__ = { |
171 update_permission = ObjectRelation('CWEType', |
164 'read': ('managers', 'users', 'guests'), |
172 description=_('groups allowed to update entities of this type')) |
165 'add': ('managers', 'users',), |
173 |
166 'update': ('managers', 'owners',), |
174 |
167 'delete': ('managers', 'owners',), |
|
168 } |
|
169 # key is a reserved word for mysql |
|
170 pkey = String(required=True, internationalizable=True, maxsize=256, |
|
171 description=_('defines what\'s the property is applied for. ' |
|
172 'You must select this first to be able to set ' |
|
173 'value')) |
|
174 value = String(internationalizable=True, maxsize=256) |
175 |
175 |
176 class relation_type(RelationType): |
176 class relation_type(RelationType): |
177 """link a relation definition to its relation type""" |
177 """link a relation definition to its relation type""" |
178 permissions = META_RTYPE_PERMS |
178 __permissions__ = PUB_SYSTEM_REL_PERMS |
179 inlined = True |
179 inlined = True |
180 |
180 |
181 class from_entity(RelationType): |
181 class from_entity(RelationType): |
182 """link a relation definition to its subject entity type""" |
182 """link a relation definition to its subject entity type""" |
183 permissions = META_RTYPE_PERMS |
183 __permissions__ = PUB_SYSTEM_REL_PERMS |
184 inlined = True |
184 inlined = True |
185 |
185 |
186 class to_entity(RelationType): |
186 class to_entity(RelationType): |
187 """link a relation definition to its object entity type""" |
187 """link a relation definition to its object entity type""" |
188 permissions = META_RTYPE_PERMS |
188 __permissions__ = PUB_SYSTEM_REL_PERMS |
189 inlined = True |
189 inlined = True |
190 |
190 |
191 class constrained_by(RelationType): |
191 class constrained_by(RelationType): |
192 """constraints applying on this relation""" |
192 """constraints applying on this relation""" |
193 permissions = META_RTYPE_PERMS |
193 __permissions__ = PUB_SYSTEM_REL_PERMS |
194 |
194 |
195 class cstrtype(RelationType): |
195 class cstrtype(RelationType): |
196 """constraint factory""" |
196 """constraint factory""" |
197 permissions = META_RTYPE_PERMS |
197 __permissions__ = PUB_SYSTEM_REL_PERMS |
198 inlined = True |
198 inlined = True |
199 |
199 |
200 class read_permission(RelationType): |
200 |
201 """core relation giving to a group the permission to read an entity or |
201 class read_permission_cwgroup(RelationDefinition): |
202 relation type |
202 """groups allowed to read entities/relations of this type""" |
203 """ |
203 __permissions__ = PUB_SYSTEM_REL_PERMS |
204 permissions = META_RTYPE_PERMS |
204 name = 'read_permission' |
205 |
205 subject = ('CWEType', 'CWAttribute', 'CWRelation') |
206 class add_permission(RelationType): |
206 object = 'CWGroup' |
207 """core relation giving to a group the permission to add an entity or |
207 cardinality = '**' |
208 relation type |
208 |
209 """ |
209 class add_permission_cwgroup(RelationDefinition): |
210 permissions = META_RTYPE_PERMS |
210 """groups allowed to add entities/relations of this type""" |
211 |
211 __permissions__ = PUB_SYSTEM_REL_PERMS |
212 class delete_permission(RelationType): |
212 name = 'add_permission' |
213 """core relation giving to a group the permission to delete an entity or |
213 subject = ('CWEType', 'CWRelation') |
214 relation type |
214 object = 'CWGroup' |
215 """ |
215 cardinality = '**' |
216 permissions = META_RTYPE_PERMS |
216 |
217 |
217 class delete_permission_cwgroup(RelationDefinition): |
218 class update_permission(RelationType): |
218 """groups allowed to delete entities/relations of this type""" |
219 """core relation giving to a group the permission to update an entity type |
219 __permissions__ = PUB_SYSTEM_REL_PERMS |
220 """ |
220 name = 'delete_permission' |
221 permissions = META_RTYPE_PERMS |
221 subject = ('CWEType', 'CWRelation') |
|
222 object = 'CWGroup' |
|
223 cardinality = '**' |
|
224 |
|
225 class update_permission_cwgroup(RelationDefinition): |
|
226 """groups allowed to update entities/relations of this type""" |
|
227 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
228 name = 'update_permission' |
|
229 subject = ('CWEType', 'CWAttribute') |
|
230 object = 'CWGroup' |
|
231 cardinality = '**' |
|
232 |
|
233 class read_permission_rqlexpr(RelationDefinition): |
|
234 """rql expression allowing to read entities/relations of this type""" |
|
235 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
236 name = 'read_permission' |
|
237 subject = ('CWEType', 'CWAttribute', 'CWRelation') |
|
238 object = 'RQLExpression' |
|
239 cardinality = '*?' |
|
240 composite = 'subject' |
|
241 |
|
242 class add_permission_rqlexpr(RelationDefinition): |
|
243 """rql expression allowing to add entities/relations of this type""" |
|
244 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
245 name = 'add_permission' |
|
246 subject = ('CWEType', 'CWRelation') |
|
247 object = 'RQLExpression' |
|
248 cardinality = '*?' |
|
249 composite = 'subject' |
|
250 |
|
251 class delete_permission_rqlexpr(RelationDefinition): |
|
252 """rql expression allowing to delete entities/relations of this type""" |
|
253 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
254 name = 'delete_permission' |
|
255 subject = ('CWEType', 'CWRelation') |
|
256 object = 'RQLExpression' |
|
257 cardinality = '*?' |
|
258 composite = 'subject' |
|
259 |
|
260 class update_permission_rqlexpr(RelationDefinition): |
|
261 """rql expression allowing to update entities/relations of this type""" |
|
262 __permissions__ = PUB_SYSTEM_REL_PERMS |
|
263 name = 'update_permission' |
|
264 subject = ('CWEType', 'CWAttribute') |
|
265 object = 'RQLExpression' |
|
266 cardinality = '*?' |
|
267 composite = 'subject' |
222 |
268 |
223 |
269 |
224 class is_(RelationType): |
270 class is_(RelationType): |
225 """core relation indicating the type of an entity |
271 """core relation indicating the type of an entity |
226 """ |
272 """ |
227 name = 'is' |
273 name = 'is' |
228 # don't explicitly set composite here, this is handled anyway |
274 # don't explicitly set composite here, this is handled anyway |
229 #composite = 'object' |
275 #composite = 'object' |
230 permissions = { |
276 __permissions__ = { |
231 'read': ('managers', 'users', 'guests'), |
277 'read': ('managers', 'users', 'guests'), |
232 'add': (), |
278 'add': (), |
233 'delete': (), |
279 'delete': (), |
234 } |
280 } |
235 cardinality = '1*' |
281 cardinality = '1*' |