Skip to main content

made_core/entities/ceremony_instance/
guard_decisions.rs

1use crate::entities::ceremony_commands::{ApproveGuard, DeferGuard};
2use crate::entities::CeremonyCommand;
3
4use super::{
5    AuditActorKind, CeremonyDefinition, CeremonyGuardDeferralContent, CeremonyInstance,
6    DomainError, GuardName, OffsetDateTime, RoleId,
7};
8
9impl CeremonyInstance {
10    /// Approving is checked the way deferring is. It used to take no
11    /// definition at all, so any name at all could be "approved" —
12    /// which wrote that name into the session context, told the caller
13    /// it had succeeded, and left a session that would never move.
14    pub fn approve_guard(
15        &mut self,
16        definition: &CeremonyDefinition,
17        guard_name: &GuardName,
18        approved_by: RoleId,
19        approved_by_kind: AuditActorKind,
20        now: OffsetDateTime,
21    ) -> Result<(), DomainError> {
22        let command = CeremonyCommand::ApproveGuard(ApproveGuard {
23            guard_name: guard_name.clone(),
24            approved_by,
25            approved_by_kind,
26            now,
27        });
28        let events = self.decide(&command, definition)?;
29        self.apply_all(&events);
30        Ok(())
31    }
32
33    pub fn defer_guard(
34        &mut self,
35        definition: &CeremonyDefinition,
36        guard_name: GuardName,
37        content: CeremonyGuardDeferralContent,
38        deferred_by: RoleId,
39        deferred_by_kind: AuditActorKind,
40        now: OffsetDateTime,
41    ) -> Result<(), DomainError> {
42        let command = CeremonyCommand::DeferGuard(DeferGuard {
43            guard_name,
44            content,
45            deferred_by,
46            deferred_by_kind,
47            now,
48        });
49        let events = self.decide(&command, definition)?;
50        self.apply_all(&events);
51        Ok(())
52    }
53}