Skip to main content

liminal_server/services/site/
outright.rs

1//! A construction act Lys answers outright is carried out at once. Lys answers outright only when
2//! a person granted the act outright, so no person decided this act: its receipt names the grant as
3//! its authority and Lys as the decider, never a person who did not see it. The grant's responsible
4//! person is recorded as answerable for the site, which is what lets them call its trial. (Lys never
5//! lets a grant's responsible person decide a draft, so a person working alone could otherwise
6//! never build anything.)
7
8use super::super::Lifecycle;
9use super::{SiteAct, SiteError};
10use crate::auth_lys::live::drafts::ApprovalTransition;
11
12impl Lifecycle {
13    /// Applies `act` under the outright `grant`, keyed by the caller's `operation`.
14    ///
15    /// # Errors
16    /// The act's own refusal (an existing site, a service not building), or a store failure.
17    pub fn apply_outright(
18        &self,
19        act: &SiteAct,
20        grant: &str,
21        operation: &str,
22        words: &str,
23        at_ms: u64,
24    ) -> Result<serde_json::Value, SiteError> {
25        let transition = ApprovalTransition {
26            draft: format!("grant:{grant}"),
27            digest: lys_pass::drafts::request_digest(words),
28            approved_by: vec!["lys".to_owned()],
29            executed_at_ms: at_ms,
30        };
31        let mut registry = self.lock()?;
32        let mut snapshot = Self::snapshot(&registry);
33        self.apply_site_act(&mut snapshot, act, &transition, at_ms, &registry.trials)?;
34        super::storage::commit(self, &mut registry, &snapshot)?;
35        drop(registry);
36        self.refresh_sites()?;
37        Ok(serde_json::json!({
38            "state": "executed",
39            "grant": grant,
40            "approved_by": "lys",
41            "responsible": act.responsible,
42            "operation": operation,
43        }))
44    }
45}
46
47#[cfg(test)]
48#[path = "outright_tests.rs"]
49mod tests;