pub fn check_chain(
governance: &Governance,
action: &ActionClass,
approvals: &[RoleApproval],
proposer: Option<&str>,
) -> Result<(), ChainRefusal>Expand description
Checks that approvals satisfy the approval chain governance names for action
(spec 3.5 §7.6, A-I23): every role the chain lists has an approval by a person holding
that role, each role’s approval by a different person, none by proposer. A role the
chain lists twice needs two people. A charter that names no chain for action needs one
owner.
An approval by an agent (a subject of kind Agent or Service, or an agent identity
such as urn:adk:agent:…) is refused outright: no agent holds a role.
§Example
use adk_core::principal::SubjectRef;
use adk_kernel::charter::{RoleApproval, check_chain};
use awp_types::{ActionClass, ApprovalChain, Governance, Role, RoleHolder};
let governance = Governance {
roles: vec![
RoleHolder { principal: "eva".into(), roles: vec![Role::Editor, Role::Publisher] },
RoleHolder { principal: "paul".into(), roles: vec![Role::Publisher] },
RoleHolder { principal: "amina".into(), roles: vec![Role::Owner] },
],
approval_chains: vec![ApprovalChain { action: ActionClass::Publish, roles: vec![Role::Editor, Role::Publisher] }],
};
let now = chrono::Utc::now();
let by = |role, who: &str| RoleApproval::new(role, SubjectRef::human(who), now);
let publish = ActionClass::Publish;
// One person cannot fill both roles.
assert!(check_chain(&governance, &publish, &[by(Role::Editor, "eva"), by(Role::Publisher, "eva")], None).is_err());
assert!(check_chain(&governance, &publish, &[by(Role::Editor, "eva"), by(Role::Publisher, "paul")], None).is_ok());
// The proposer cannot approve.
assert!(check_chain(&governance, &publish, &[by(Role::Editor, "eva"), by(Role::Publisher, "paul")], Some("paul")).is_err());§Errors
Returns the ChainRefusal naming the first fault found.