513 # use super session to by-pass security checks |
513 # use super session to by-pass security checks |
514 session.super_session.add_relation(entity.eid, 'in_state', |
514 session.super_session.add_relation(entity.eid, 'in_state', |
515 state.eid) |
515 state.eid) |
516 |
516 |
517 |
517 |
|
518 def set_initial_state_after_add(session, entity): |
|
519 SetInitialStateOp(session, entity=entity) |
|
520 |
|
521 |
518 def before_add_in_state(session, eidfrom, rtype, eidto): |
522 def before_add_in_state(session, eidfrom, rtype, eidto): |
519 """check state apply""" |
523 """check state apply""" |
520 nocheck = session.transaction_data.setdefault('skip-security', ()) |
524 nocheck = session.transaction_data.setdefault('skip-security', ()) |
521 if (eidfrom, 'in_state', eidto) in nocheck: |
525 if (eidfrom, 'in_state', eidto) in nocheck: |
522 # state changed through TrInfo insertion, so we already know it's ok |
526 # state changed through TrInfo insertion, so we already know it's ok |
533 else: |
537 else: |
534 msg = session._("state doesn't belong to entity's workflow. You may " |
538 msg = session._("state doesn't belong to entity's workflow. You may " |
535 "want to set a custom workflow for this entity first.") |
539 "want to set a custom workflow for this entity first.") |
536 raise ValidationError(eidfrom, {'in_state': msg}) |
540 raise ValidationError(eidfrom, {'in_state': msg}) |
537 |
541 |
538 def set_initial_state_after_add(session, entity): |
|
539 SetInitialStateOp(session, entity=entity) |
|
540 |
|
541 |
542 |
542 class WorkflowChangedOp(PreCommitOperation): |
543 class WorkflowChangedOp(PreCommitOperation): |
543 """fix entity current state when changing its workflow""" |
544 """fix entity current state when changing its workflow""" |
544 |
545 |
545 def precommit_event(self): |
546 def precommit_event(self): |
|
547 # notice that enforcement that new workflow apply to the entity's type is |
|
548 # done by schema rule, no need to check it here |
546 session = self.session |
549 session = self.session |
547 pendingeids = session.transaction_data.get('pendingeids', ()) |
550 pendingeids = session.transaction_data.get('pendingeids', ()) |
548 if self.eid in pendingeids: |
551 if self.eid in pendingeids: |
549 return |
552 return |
550 entity = session.entity_from_eid(self.eid) |
553 entity = session.entity_from_eid(self.eid) |