server/schemahooks.py
changeset 2455 5346d9f3d5ec
parent 2250 bc6fc4d6bcac
child 2456 aa25d6b244c8
equal deleted inserted replaced
2454:3648b718a0d3 2455:5346d9f3d5ec
   187     session.execute('DELETE CWRelation X WHERE X relation_type Y, Y eid %(x)s',
   187     session.execute('DELETE CWRelation X WHERE X relation_type Y, Y eid %(x)s',
   188                     {'x': eid})
   188                     {'x': eid})
   189     DeleteCWRTypeOp(session, name)
   189     DeleteCWRTypeOp(session, name)
   190 
   190 
   191 
   191 
   192 class DelRelationDefOp(SchemaOperation):
   192 class DeleteRelationDefOp(SchemaOperation):
   193     """actually remove the relation definition from the application's schema"""
   193     """actually remove the relation definition from the application's schema"""
   194     def commit_event(self):
   194     def commit_event(self):
   195         subjtype, rtype, objtype = self.kobj
   195         subjtype, rtype, objtype = self.kobj
   196         try:
   196         try:
   197             self.schema.del_relation_def(subjtype, rtype, objtype)
   197             self.schema.del_relation_def(subjtype, rtype, objtype)
   236     elif lastrel:
   236     elif lastrel:
   237         DropTableOp(session, table='%s_relation' % rschema.type)
   237         DropTableOp(session, table='%s_relation' % rschema.type)
   238     # if this is the last instance, drop associated relation type
   238     # if this is the last instance, drop associated relation type
   239     if lastrel and not rteid in pendings:
   239     if lastrel and not rteid in pendings:
   240         execute('DELETE CWRType X WHERE X eid %(x)s', {'x': rteid}, 'x')
   240         execute('DELETE CWRType X WHERE X eid %(x)s', {'x': rteid}, 'x')
   241     DelRelationDefOp(session, (subjschema, rschema, objschema))
   241     DeleteRelationDefOp(session, (subjschema, rschema, objschema))
   242 
   242 
   243 
   243 
   244 # addition ####################################################################
   244 # addition ####################################################################
   245 
   245 
   246 class AddCWETypeOp(EarlySchemaOperation):
   246 class AddCWETypeOp(EarlySchemaOperation):
   881         except ValueError:
   881         except ValueError:
   882             self.error('can\'t remove permission %s on %s to group %s',
   882             self.error('can\'t remove permission %s on %s to group %s',
   883                 self.perm, erschema.type, self.group)
   883                 self.perm, erschema.type, self.group)
   884 
   884 
   885 
   885 
   886 class DelRQLExpressionPermissionOp(AddRQLExpressionPermissionOp):
   886 class DeleteRQLExpressionPermissionOp(AddRQLExpressionPermissionOp):
   887     """synchronize schema when a *_permission relation has been deleted from an rql expression"""
   887     """synchronize schema when a *_permission relation has been deleted from an rql expression"""
   888 
   888 
   889     def commit_event(self):
   889     def commit_event(self):
   890         """the observed connections pool has been commited"""
   890         """the observed connections pool has been commited"""
   891         try:
   891         try:
   917     if session.describe(object)[0] == 'CWGroup':
   917     if session.describe(object)[0] == 'CWGroup':
   918         DelGroupPermissionOp(session, perm, subject, object)
   918         DelGroupPermissionOp(session, perm, subject, object)
   919     else: # RQLExpression
   919     else: # RQLExpression
   920         expr = session.execute('Any EXPR WHERE X eid %(x)s, X expression EXPR',
   920         expr = session.execute('Any EXPR WHERE X eid %(x)s, X expression EXPR',
   921                                {'x': object}, 'x')[0][0]
   921                                {'x': object}, 'x')[0][0]
   922         DelRQLExpressionPermissionOp(session, perm, subject, expr)
   922         DeleteRQLExpressionPermissionOp(session, perm, subject, expr)
   923 
   923 
   924 
   924 
   925 def rebuild_infered_relations(session, subject, rtype, object):
   925 def rebuild_infered_relations(session, subject, rtype, object):
   926     # registering a schema operation will trigger a call to
   926     # registering a schema operation will trigger a call to
   927     # repo.set_schema() on commit which will in turn rebuild
   927     # repo.set_schema() on commit which will in turn rebuild