server/repository.py
branchstable
changeset 7502 e7190f7e850e
parent 7501 2983dd24494a
child 7503 bc30c2faaadc
equal deleted inserted replaced
7501:2983dd24494a 7502:e7190f7e850e
   101     # XXX we should imo rely on the orm to first fetch existing entity if any
   101     # XXX we should imo rely on the orm to first fetch existing entity if any
   102     # then delete it.
   102     # then delete it.
   103     if session.is_internal_session \
   103     if session.is_internal_session \
   104            or not session.is_hook_category_activated('activeintegrity'):
   104            or not session.is_hook_category_activated('activeintegrity'):
   105         return
   105         return
   106     card = session.schema_rproperty(rtype, eidfrom, eidto, 'cardinality')
   106     rdef = session.rtype_eids_rdef(rtype, eidfrom, eidto)
       
   107     card = rdef.cardinality
   107     # one may be tented to check for neweids but this may cause more than one
   108     # one may be tented to check for neweids but this may cause more than one
   108     # relation even with '1?'  cardinality if thoses relations are added in the
   109     # relation even with '1?'  cardinality if thoses relations are added in the
   109     # same transaction where the entity is being created. This never occurs from
   110     # same transaction where the entity is being created. This never occurs from
   110     # the web interface but may occurs during test or dbapi connection (though
   111     # the web interface but may occurs during test or dbapi connection (though
   111     # not expected for this).  So: don't do it, we pretend to ensure repository
   112     # not expected for this).  So: don't do it, we pretend to ensure repository
   113     #
   114     #
   114     # notes:
   115     # notes:
   115     # * inlined relations will be implicitly deleted for the subject entity
   116     # * inlined relations will be implicitly deleted for the subject entity
   116     # * we don't want read permissions to be applied but we want delete
   117     # * we don't want read permissions to be applied but we want delete
   117     #   permission to be checked
   118     #   permission to be checked
   118     if card[0] in '1?' and not session.repo.schema.rschema(rtype).inlined:
   119     if card[0] in '1?' and not rdef.rtype.inlined:
   119         with security_enabled(session, read=False):
   120         with security_enabled(session, read=False):
   120             session.execute('DELETE X %s Y WHERE X eid %%(x)s, '
   121             session.execute('DELETE X %s Y WHERE X eid %%(x)s, '
   121                             'NOT Y eid %%(y)s' % rtype,
   122                             'NOT Y eid %%(y)s' % rtype,
   122                                 {'x': eidfrom, 'y': eidto})
   123                                 {'x': eidfrom, 'y': eidto})
   123     if card[1] in '1?':
   124     if card[1] in '1?':