use super::super::Lifecycle;
use super::{SiteAct, SiteError};
use crate::auth_lys::live::drafts::ApprovalTransition;
impl Lifecycle {
pub fn apply_outright(
&self,
act: &SiteAct,
grant: &str,
operation: &str,
words: &str,
at_ms: u64,
) -> Result<serde_json::Value, SiteError> {
self.apply_now(
act,
&ApprovalTransition {
draft: format!("grant:{grant}"),
digest: lys_pass::drafts::request_digest(words),
approved_by: vec!["lys".to_owned()],
executed_at_ms: at_ms,
},
at_ms,
)?;
Ok(serde_json::json!({
"state": "executed",
"grant": grant,
"approved_by": "lys",
"responsible": act.responsible,
"operation": operation,
}))
}
pub fn apply_declared(
&self,
act: &SiteAct,
operation: &str,
at_ms: u64,
) -> Result<serde_json::Value, SiteError> {
let words = serde_json::to_string(act).map_err(|_| SiteError::Store)?;
if words.len() > self.site_bindings()?.limits.request_bytes.get() {
return Err(SiteError::Bound("request_bytes"));
}
self.apply_now(
act,
&ApprovalTransition {
draft: format!("{}:{operation}", act.holder),
digest: lys_pass::drafts::request_digest(&words),
approved_by: vec![act.holder.clone()],
executed_at_ms: at_ms,
},
at_ms,
)?;
Ok(serde_json::json!({
"state": "executed",
"grant": crate::agents::open_session::OPEN_GRANT,
"approved_by": act.holder,
"responsible": act.responsible,
"operation": operation,
}))
}
fn apply_now(
&self,
act: &SiteAct,
transition: &ApprovalTransition,
at_ms: u64,
) -> Result<(), SiteError> {
let mut registry = self.lock()?;
let mut snapshot = Self::snapshot(®istry);
self.apply_site_act(&mut snapshot, act, transition, at_ms, ®istry.trials)?;
super::storage::commit(self, &mut registry, &snapshot)?;
drop(registry);
self.refresh_sites()
}
}
#[cfg(test)]
#[path = "outright_tests.rs"]
mod tests;