dpm_engine/run/
transition.rs1use super::RunError;
4use dpm_model::{ActorId, ActorKind, RunId, RunRecord, RunState};
5
6pub fn authorize(
11 record: &RunRecord,
12 writer: &ActorId,
13 action: &'static str,
14) -> Result<(), RunError> {
15 authorize_writer(writer, &record.executor, record.id, action)
16}
17
18pub(super) fn authorize_writer(
19 writer: &ActorId,
20 executor: &ActorId,
21 run: RunId,
22 action: &'static str,
23) -> Result<(), RunError> {
24 if writer == executor || writer.kind != ActorKind::Agent {
25 return Ok(());
26 }
27 Err(RunError::ActorNotAllowed {
28 actor: writer.clone(),
29 action,
30 run,
31 executor: executor.clone(),
32 })
33}
34
35pub fn check_transition(run: RunId, from: RunState, to: RunState) -> Result<(), RunError> {
40 if from.is_terminal() {
41 return Err(RunError::Terminal { run, state: from });
42 }
43 if from == to {
44 return Err(RunError::InvalidTransition { run, from, to });
45 }
46 Ok(())
47}