server/hooks.py
branch3.5
changeset 3039 7d5a4d27d052
parent 2992 a5b8bf107a1a
child 3071 6ad4e6d4df86
equal deleted inserted replaced
3038:1261c3df0e5a 3039:7d5a4d27d052
   423 def _change_state(session, x, oldstate, newstate):
   423 def _change_state(session, x, oldstate, newstate):
   424     nocheck = session.transaction_data.setdefault('skip-security', set())
   424     nocheck = session.transaction_data.setdefault('skip-security', set())
   425     nocheck.add((x, 'in_state', oldstate))
   425     nocheck.add((x, 'in_state', oldstate))
   426     nocheck.add((x, 'in_state', newstate))
   426     nocheck.add((x, 'in_state', newstate))
   427     # delete previous state first in case we're using a super session
   427     # delete previous state first in case we're using a super session
   428     session.delete_relation(x, 'in_state', oldstate)
   428     fromsource = session.describe(x)[1]
       
   429     # don't try to remove previous state if in_state isn't stored in the system
       
   430     # source
       
   431     if fromsource == 'system' or \
       
   432        not session.repo.sources_by_uri[fromsource].support_relation('in_state'):
       
   433         session.delete_relation(x, 'in_state', oldstate)
   429     session.add_relation(x, 'in_state', newstate)
   434     session.add_relation(x, 'in_state', newstate)
   430 
   435 
   431 
   436 
   432 def before_add_trinfo(session, entity):
   437 def before_add_trinfo(session, entity):
   433     """check the transition is allowed, add missing information. Expect that:
   438     """check the transition is allowed, add missing information. Expect that:
   512 def after_add_trinfo(session, entity):
   517 def after_add_trinfo(session, entity):
   513     """change related entity state"""
   518     """change related entity state"""
   514     _change_state(session, entity['wf_info_for'],
   519     _change_state(session, entity['wf_info_for'],
   515                   entity['from_state'], entity['to_state'])
   520                   entity['from_state'], entity['to_state'])
   516     forentity = session.entity_from_eid(entity['wf_info_for'])
   521     forentity = session.entity_from_eid(entity['wf_info_for'])
   517     assert forentity.current_state.eid == entity['to_state']
   522     assert forentity.current_state.eid == entity['to_state'], forentity.current_state.name
   518     if forentity.main_workflow.eid != forentity.current_workflow.eid:
   523     if forentity.main_workflow.eid != forentity.current_workflow.eid:
   519         # we're in a subworkflow, check if we've reached an exit point
   524         # we're in a subworkflow, check if we've reached an exit point
   520         wftr = forentity.subworkflow_input_transition()
   525         wftr = forentity.subworkflow_input_transition()
   521         if wftr is None:
   526         if wftr is None:
   522             # inconsistency detected
   527             # inconsistency detected