liminal-server 0.24.9

Standalone server for the liminal messaging bus
Documentation
//! A construction act Lys answers outright is carried out at once. Lys answers outright only when
//! a person granted the act outright, so no person decided this act: its receipt names the grant as
//! its authority and Lys as the decider, never a person who did not see it. The grant's responsible
//! person is recorded as answerable for the site, which is what lets them call its trial. (Lys never
//! lets a grant's responsible person decide a draft, so a person working alone could otherwise
//! never build anything.)

use super::super::Lifecycle;
use super::{SiteAct, SiteError};
use crate::auth_lys::live::drafts::ApprovalTransition;

impl Lifecycle {
    /// Applies `act` under the outright `grant`, keyed by the caller's `operation`.
    ///
    /// # Errors
    /// The act's own refusal (an existing site, a service not building), or a store failure.
    pub fn apply_outright(
        &self,
        act: &SiteAct,
        grant: &str,
        operation: &str,
        words: &str,
        at_ms: u64,
    ) -> Result<serde_json::Value, SiteError> {
        let transition = ApprovalTransition {
            draft: format!("grant:{grant}"),
            digest: lys_pass::drafts::request_digest(words),
            approved_by: vec!["lys".to_owned()],
            executed_at_ms: at_ms,
        };
        let mut registry = self.lock()?;
        let mut snapshot = Self::snapshot(&registry);
        self.apply_site_act(&mut snapshot, act, &transition, at_ms, &registry.trials)?;
        super::storage::commit(self, &mut registry, &snapshot)?;
        drop(registry);
        self.refresh_sites()?;
        Ok(serde_json::json!({
            "state": "executed",
            "grant": grant,
            "approved_by": "lys",
            "responsible": act.responsible,
            "operation": operation,
        }))
    }
}

#[cfg(test)]
#[path = "outright_tests.rs"]
mod tests;