brokerd: answers carry the Mattermost post; Table::contains
Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//! gone. In memory only.
|
||||
|
||||
use crate::policy::{Ask, Decision};
|
||||
use proto::{DenyReason, PendingApproval, Timestamp};
|
||||
use proto::{DecisionRecord, DenyReason, PendingApproval, Timestamp};
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::mpsc::{Receiver, Sender, channel};
|
||||
use std::sync::{Mutex, MutexGuard};
|
||||
@@ -14,6 +14,29 @@ pub enum Verdict {
|
||||
Denied(DenyReason),
|
||||
}
|
||||
|
||||
/// An owner's answer to a pending call.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum Answer {
|
||||
/// `by` is "bxctl" or a Mattermost user id; `post` the Mattermost post that answered.
|
||||
Approved {
|
||||
by: Option<String>,
|
||||
post: Option<String>,
|
||||
},
|
||||
Refused {
|
||||
by: Option<String>,
|
||||
post: Option<String>,
|
||||
reason: Option<String>,
|
||||
},
|
||||
Expired,
|
||||
}
|
||||
|
||||
/// What an approval leaves: the verdict (run or deny) and the record written.
|
||||
#[derive(Debug)]
|
||||
pub struct Answered {
|
||||
pub verdict: Verdict,
|
||||
pub outcome: DecisionRecord,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Entry {
|
||||
pub info: PendingApproval,
|
||||
@@ -52,6 +75,11 @@ impl Table {
|
||||
receiver
|
||||
}
|
||||
|
||||
/// Is approval `id` still pending? Only a hint: it may be taken the moment after.
|
||||
pub fn contains(&self, id: u64) -> bool {
|
||||
self.lock().contains_key(&id)
|
||||
}
|
||||
|
||||
pub fn take(&self, id: u64) -> Option<Entry> {
|
||||
self.lock().remove(&id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user