schema.py
branchstable
changeset 4574 2380444d982c
parent 4570 ede247bbbf62
child 4575 4a7fe84f7803
equal deleted inserted replaced
4573:fc6bb020e60e 4574:2380444d982c
   281         for group_or_rqlexpr in groups:
   281         for group_or_rqlexpr in groups:
   282             if action == 'read' and \
   282             if action == 'read' and \
   283                    isinstance(group_or_rqlexpr, RQLExpression):
   283                    isinstance(group_or_rqlexpr, RQLExpression):
   284                 msg = "can't use rql expression for read permission of %s"
   284                 msg = "can't use rql expression for read permission of %s"
   285                 raise BadSchemaDefinition(msg % self)
   285                 raise BadSchemaDefinition(msg % self)
   286             elif self.final and isinstance(group_or_rqlexpr, RRQLExpression):
   286             if self.final and isinstance(group_or_rqlexpr, RRQLExpression):
   287                 if schema.reading_from_database:
   287                 msg = "can't use RRQLExpression on %s, use an ERQLExpression"
   288                     # we didn't have final relation earlier, so turn
   288                 raise BadSchemaDefinition(msg % self)
   289                     # RRQLExpression into ERQLExpression now
   289             if not self.final and isinstance(group_or_rqlexpr, ERQLExpression):
   290                     rqlexpr = group_or_rqlexpr
       
   291                     newrqlexprs = [x for x in self.get_rqlexprs(action)
       
   292                                    if not x is rqlexpr]
       
   293                     newrqlexprs.append(ERQLExpression(rqlexpr.expression,
       
   294                                                       rqlexpr.mainvars,
       
   295                                                       rqlexpr.eid))
       
   296                     self.set_rqlexprs(action, newrqlexprs)
       
   297                 else:
       
   298                     msg = "can't use RRQLExpression on %s, use an ERQLExpression"
       
   299                     raise BadSchemaDefinition(msg % self)
       
   300             elif not self.final and \
       
   301                      isinstance(group_or_rqlexpr, ERQLExpression):
       
   302                 msg = "can't use ERQLExpression on %s, use a RRQLExpression"
   290                 msg = "can't use ERQLExpression on %s, use a RRQLExpression"
   303                 raise BadSchemaDefinition(msg % self)
   291                 raise BadSchemaDefinition(msg % self)
   304 RelationDefinitionSchema.check_permission_definitions = check_permission_definitions
   292 RelationDefinitionSchema.check_permission_definitions = check_permission_definitions
   305 
   293 
   306 
   294 
   312     def __init__(self, schema=None, edef=None, eid=None, **kwargs):
   300     def __init__(self, schema=None, edef=None, eid=None, **kwargs):
   313         super(CubicWebEntitySchema, self).__init__(schema, edef, **kwargs)
   301         super(CubicWebEntitySchema, self).__init__(schema, edef, **kwargs)
   314         if eid is None and edef is not None:
   302         if eid is None and edef is not None:
   315             eid = getattr(edef, 'eid', None)
   303             eid = getattr(edef, 'eid', None)
   316         self.eid = eid
   304         self.eid = eid
   317         # take care: no _groups attribute when deep-copying
   305 
   318         if getattr(self, 'permissions', None):
   306     def check_permission_definitions(self):
   319             for groups in self.permissions.itervalues():
   307         super(CubicWebEntitySchema, self).check_permission_definitions()
   320                 for group_or_rqlexpr in groups:
   308         for groups in self.permissions.itervalues():
   321                     if isinstance(group_or_rqlexpr, RRQLExpression):
   309             for group_or_rqlexpr in groups:
   322                         msg = "can't use RRQLExpression on an entity type, use an ERQLExpression (%s)"
   310                 if isinstance(group_or_rqlexpr, RRQLExpression):
   323                         raise BadSchemaDefinition(msg % self.type)
   311                     msg = "can't use RRQLExpression on %s, use an ERQLExpression"
       
   312                     raise BadSchemaDefinition(msg % self.type)
   324 
   313 
   325     def attribute_definitions(self):
   314     def attribute_definitions(self):
   326         """return an iterator on attribute definitions
   315         """return an iterator on attribute definitions
   327 
   316 
   328         attribute relations are a subset of subject relations where the
   317         attribute relations are a subset of subject relations where the