class UserState(StateMachine): REGISTERED = 0 ACTIVE = 1 BLOCKED = 2 enable = transition(REGISTERED, ACTIVE)() disable = transition(ACTIVE, BLOCKED)()
class VulnerabilityState(StateMachine): NEW = 0 NEEDS_IMPROVEMENT = 1 READY = 2 IN_REVIEW = 3 REVIEWED = 4 PUBLISHED = 5 ARCHIVED = 6 def __init__(self, vulnerability): super().__init__() self._vulnerability = vulnerability self.current_state = vulnerability.state @event(NEW) def on_new(self): LOG.info('Vulnerability entered NEW state') new_to_ready = transition(NEW, READY)() needs_improvement_to_ready = transition(NEEDS_IMPROVEMENT, READY)() in_review_to_reviewed = transition(IN_REVIEW, REVIEWED)() reviewed_to_needs_improvement = transition(REVIEWED, NEEDS_IMPROVEMENT)() published_to_archived = transition(PUBLISHED, ARCHIVED)() @transition(REVIEWED, PUBLISHED) def check_publishing_possible(self, current_state, next_state): # TODO: check for merge conflicts or other issues return self._vulnerability.version is not None @transition(READY, READY) def check_can_update_proposal(self, current_state, next_state): # Ready state means that no new reviewer is reviewing this. # The entry can be freely updated by the author in the meantime. return True @transition(IN_REVIEW, READY) def check_return_to_pool(self, current_state, next_state): return self._vulnerability.reviewer is None @transition(IN_REVIEW, NEEDS_IMPROVEMENT) def check_pushback(self, current_state, next_state): return bool(self._vulnerability.review_feedback ) and self._vulnerability.reviewer is not None @transition(READY, IN_REVIEW) def check_accept_review(self, current_state, next_state): return self._vulnerability.reviewer is not None @transition(PUBLISHED, ARCHIVED) def check_archiving_possible(self, current_state, next_state): other_published_entry_exists = bool( Vulnerability.query.filter( Vulnerability.id != self._vulnerability.id, Vulnerability.vcdb_id == self._vulnerability.vcdb_id, Vulnerability.state == VulnerabilityState.PUBLISHED).first()) return other_published_entry_exists
class VulnerabilityState(StateMachine): NEW = 0 READY = 1 IN_REVIEW = 2 REVIEWED = 3 PUBLISHED = 4 ARCHIVED = 5 def __init__(self, vulnerability): super().__init__() self._vulnerability = vulnerability self.current_state = vulnerability.state @event(NEW) def on_new(self): LOG.info('Vulnerability entered NEW state') new_to_ready = transition(NEW, READY)() review_to_reviewed = transition(IN_REVIEW, REVIEWED)() reviewed_to_new = transition(REVIEWED, NEW)() published_to_archived = transition(PUBLISHED, ARCHIVED)() @transition(REVIEWED, PUBLISHED) def check_publishing_possible(self, current_state, next_state): # TODO: check for merge conflicts or other issues return self._vulnerability.version is not None @transition(READY, READY) @transition(IN_REVIEW, READY) def check_return_to_pool(self, current_state, next_state): return self._vulnerability.reviewer is None @transition(IN_REVIEW, NEW) def check_pushback(self, current_state, next_state): return bool(self._vulnerability.review_feedback ) and self._vulnerability.reviewer is not None @transition(READY, IN_REVIEW) def check_accept_review(self, current_state, next_state): return self._vulnerability.reviewer is not None @transition(PUBLISHED, ARCHIVED) def check_archiving_possible(self, current_state, next_state): other_published_entries = Vulnerability.query.filter( Vulnerability.id != self._vulnerability.id, Vulnerability.vcdb_id == self._vulnerability.vcdb_id, Vulnerability.state == VulnerabilityState.PUBLISHED).exists() return other_published_entries
class UserState(StateMachine): REGISTERED = 0 ACTIVE = 1 BLOCKED = 2 FIRST_LOGIN = 3 @transition(BLOCKED, ACTIVE) @transition(REGISTERED, FIRST_LOGIN) @transition(FIRST_LOGIN, ACTIVE) def enable(self, current_state, next_state): # pylint: disable=no-self-use del current_state, next_state return True disable = transition(ACTIVE, BLOCKED)()
class VulnerabilityState(StateMachine): NEW = 0 READY = 1 IN_REVIEW = 2 REVIEWED = 3 PUBLISHED = 4 ARCHIVED = 5 @event(NEW) def on_new(self): LOG.info('Vulnerability entered NEW state') new_to_ready = transition(NEW, READY)() ready_to_review = transition(READY, IN_REVIEW)() review_to_new = transition(IN_REVIEW, NEW)() review_to_reviewed = transition(IN_REVIEW, REVIEWED)() reviewed_to_new = transition(REVIEWED, NEW)() published_to_archived = transition(PUBLISHED, ARCHIVED)() @transition(REVIEWED, PUBLISHED) def check_publishing_possible(self, current_state, next_state): # TODO: check for merge conflicts or other issues pass
o_disk_to_audio = 'do_disk_to_audio' o_configure = 'configure' # Conditions c_is_disk_detected = 'is_disk_detected' c_is_disk_mounted = 'is_disk_mounted' # Transitions t_setup = 'setup' t_record = 'record' t_idle = 'idle' transitions = [ # Startup Step 1 (Detect and Mount AudioMoth) transition('setup', 'unknown', 'configuring') .after('setup_moth').get(), transition('setup_moth', 'configuring', 'configuring_moth') .after('setup_detect_moth').get(), transition('setup_detect_moth', 'configuring_moth', 'configuring_moth_detected') .prepare(['do_audio_to_disk', 'do_detect_moth']) .conditions('is_moth_detected') .after('setup_mount_moth').get(), transition('setup_detect_moth', 'configuring_moth', 'configuring_moth_error_unresponsive') .after('setup_reset_moth').get(), transition('setup_mount_moth', 'configuring_moth_detected', 'configuring_moth_mounted') .prepare('do_mount_moth') .conditions(['is_moth_mounted'])