server/hooks.py
branchstable
changeset 3568 87a7ca9d8ce6
parent 3554 26e586f3c15c
child 3617 9036a8fbbd57
equal deleted inserted replaced
3567:c43ce7949acf 3568:87a7ca9d8ce6
   171         session = self.session
   171         session = self.session
   172         # don't do anything if the entity is being created or deleted
   172         # don't do anything if the entity is being created or deleted
   173         if not (self.eid in session.transaction_data.get('pendingeids', ()) or
   173         if not (self.eid in session.transaction_data.get('pendingeids', ()) or
   174                 self.eid in session.transaction_data.get('neweids', ())):
   174                 self.eid in session.transaction_data.get('neweids', ())):
   175             etype = session.describe(self.eid)[0]
   175             etype = session.describe(self.eid)[0]
   176             session.unsafe_execute('DELETE %s X WHERE X eid %%(x)s, NOT %s'
   176             if self.role == 'subject':
   177                                    % (etype, self.relation),
   177                 rql = 'DELETE %s X WHERE X eid %%(x)s, NOT X %s Y'
   178                                    {'x': self.eid}, 'x')
   178             else: # self.role == 'object':
       
   179                 rql = 'DELETE %s X WHERE X eid %%(x)s, NOT Y %s X'
       
   180             session.unsafe_execute(rql % (etype, self.rtype), {'x': self.eid}, 'x')
   179 
   181 
   180 
   182 
   181 def handle_composite_before_del_relation(session, eidfrom, rtype, eidto):
   183 def handle_composite_before_del_relation(session, eidfrom, rtype, eidto):
   182     """delete the object of composite relation"""
   184     """delete the object of composite relation"""
       
   185     # if the relation is being delete, don't delete composite's components
       
   186     # automatically
       
   187     pendingrdefs = session.transaction_data.get('pendingrdefs', ())
       
   188     if (session.describe(eidfrom)[0], rtype, session.describe(eidto)[0]) in pendingrdefs:
       
   189         return
   183     composite = rproperty(session, rtype, eidfrom, eidto, 'composite')
   190     composite = rproperty(session, rtype, eidfrom, eidto, 'composite')
   184     if composite == 'subject':
   191     if composite == 'subject':
   185         DelayedDeleteOp(session, eid=eidto, relation='Y %s X' % rtype)
   192         DelayedDeleteOp(session, eid=eidto, rtype=rtype, role='object')
   186     elif composite == 'object':
   193     elif composite == 'object':
   187         DelayedDeleteOp(session, eid=eidfrom, relation='X %s Y' % rtype)
   194         DelayedDeleteOp(session, eid=eidfrom, rtype=rtype, role='subject')
   188 
   195 
   189 
   196 
   190 def before_del_group(session, eid):
   197 def before_del_group(session, eid):
   191     """check that we don't remove the owners group"""
   198     """check that we don't remove the owners group"""
   192     check_internal_entity(session, eid, ('owners',))
   199     check_internal_entity(session, eid, ('owners',))
   315             cardindex = 1
   322             cardindex = 1
   316             opcls = CheckORelationOp
   323             opcls = CheckORelationOp
   317         card = rschema.rproperty(subjtype, objtype, 'cardinality')
   324         card = rschema.rproperty(subjtype, objtype, 'cardinality')
   318         if card[cardindex] in '1+':
   325         if card[cardindex] in '1+':
   319             checkrel_if_necessary(session, opcls, rschema.type, eid)
   326             checkrel_if_necessary(session, opcls, rschema.type, eid)
   320 
       
   321 
   327 
   322 def cardinalitycheck_before_del_relation(session, eidfrom, rtype, eidto):
   328 def cardinalitycheck_before_del_relation(session, eidfrom, rtype, eidto):
   323     """check cardinalities are satisfied"""
   329     """check cardinalities are satisfied"""
   324     if rtype in DONT_CHECK_RTYPES_ON_DEL:
   330     if rtype in DONT_CHECK_RTYPES_ON_DEL:
   325         return
   331         return
   542 def after_add_trinfo(session, entity):
   548 def after_add_trinfo(session, entity):
   543     """change related entity state"""
   549     """change related entity state"""
   544     _change_state(session, entity['wf_info_for'],
   550     _change_state(session, entity['wf_info_for'],
   545                   entity['from_state'], entity['to_state'])
   551                   entity['from_state'], entity['to_state'])
   546     forentity = session.entity_from_eid(entity['wf_info_for'])
   552     forentity = session.entity_from_eid(entity['wf_info_for'])
   547     assert forentity.current_state.eid == entity['to_state'], forentity.current_state.name
   553     assert forentity.current_state.eid == entity['to_state'], (
       
   554         forentity.eid, forentity.current_state.name)
   548     if forentity.main_workflow.eid != forentity.current_workflow.eid:
   555     if forentity.main_workflow.eid != forentity.current_workflow.eid:
   549         # we're in a subworkflow, check if we've reached an exit point
   556         # we're in a subworkflow, check if we've reached an exit point
   550         wftr = forentity.subworkflow_input_transition()
   557         wftr = forentity.subworkflow_input_transition()
   551         if wftr is None:
   558         if wftr is None:
   552             # inconsistency detected
   559             # inconsistency detected