This commit is contained in:
parent
c646ccc0ec
commit
961dc870da
6 changed files with 90 additions and 1 deletions
|
|
@ -1082,6 +1082,12 @@ pub trait Store {
|
|||
// The live network state a service reads (never mutates directly; changes go out
|
||||
// as actions on the ServiceCtx).
|
||||
pub trait NetView {
|
||||
// Account names of the network's configured operators (MemoServ STAFF). The
|
||||
// default is empty; the engine's live view overrides it. Runtime OPER grants
|
||||
// are separate (Store::opers_list) — a caller unions the two.
|
||||
fn oper_accounts(&self) -> Vec<String> {
|
||||
Vec::new()
|
||||
}
|
||||
fn uid_by_nick(&self, nick: &str) -> Option<&str>;
|
||||
fn nick_of(&self, uid: &str) -> Option<&str>;
|
||||
fn host_of(&self, uid: &str) -> Option<&str>;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ mod check;
|
|||
mod info;
|
||||
#[path = "sendall.rs"]
|
||||
mod sendall;
|
||||
#[path = "staff.rs"]
|
||||
mod staff;
|
||||
#[path = "ignore.rs"]
|
||||
mod ignore;
|
||||
#[path = "set.rs"]
|
||||
|
|
@ -42,6 +44,7 @@ const TOPICS: &[HelpEntry] = &[
|
|||
HelpEntry { cmd: "CHECK", summary: "see if a memo was read", detail: "Syntax: \x02CHECK <nick>\x02\nReports whether the last memo you sent them has been read." },
|
||||
HelpEntry { cmd: "INFO", summary: "your mailbox summary", detail: "Syntax: \x02INFO\x02\nShows how many memos you have, how many are unread, and your capacity." },
|
||||
HelpEntry { cmd: "SENDALL", summary: "memo every account (admin)", detail: "Syntax: \x02SENDALL <text>\x02\nLeaves a memo on every registered account. Requires the admin privilege." },
|
||||
HelpEntry { cmd: "STAFF", summary: "memo every operator (admin)", detail: "Syntax: \x02STAFF <text>\x02\nLeaves a memo on every operator's account. Requires the admin privilege." },
|
||||
HelpEntry { cmd: "IGNORE", summary: "block memos from an account", detail: "Syntax: \x02IGNORE ADD <nick> | DEL <nick> | LIST\x02\nMemos from an ignored account are silently dropped." },
|
||||
HelpEntry { cmd: "SET", summary: "your memo preferences", detail: "Syntax: \x02SET NOTIFY {ON|OFF}\x02, \x02SET LIMIT <n>|NONE\x02\nControls new-memo notifications and your mailbox size cap." },
|
||||
];
|
||||
|
|
@ -65,7 +68,7 @@ impl Service for MemoServ {
|
|||
(BLURB, TOPICS)
|
||||
}
|
||||
|
||||
fn on_command(&mut self, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, _net: &dyn NetView, db: &mut dyn Store) {
|
||||
fn on_command(&mut self, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
|
||||
let me = self.uid.as_str();
|
||||
let cmd = args.first().map(|s| s.to_ascii_uppercase());
|
||||
if matches!(cmd.as_deref(), Some("HELP") | None) {
|
||||
|
|
@ -87,6 +90,7 @@ impl Service for MemoServ {
|
|||
Some("CHECK") => check::handle(me, from, account, args, ctx, db),
|
||||
Some("INFO") => info::handle(me, from, account, ctx, db),
|
||||
Some("SENDALL") => sendall::handle(me, from, account, args, ctx, db),
|
||||
Some("STAFF") => staff::handle(me, from, account, args, ctx, net, db),
|
||||
Some("IGNORE") => ignore::handle(me, from, account, args, ctx, db),
|
||||
Some("SET") => set::handle(me, from, account, args, ctx, db),
|
||||
Some(other) => ctx.notice(me, from.uid, format!("I don't know the command \x02{other}\x02. Try \x02HELP\x02.")),
|
||||
|
|
|
|||
33
modules/memoserv/src/staff.rs
Normal file
33
modules/memoserv/src/staff.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use echo_api::{NetView, Priv, Sender, ServiceCtx, Store};
|
||||
|
||||
// STAFF <text>: leave a memo on every operator's account. Admin-only, for
|
||||
// notes to the staff team that persist until read. Recipients are the union of
|
||||
// the configured operators and any runtime OPER grants.
|
||||
pub fn handle(me: &str, from: &Sender, account: &str, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
|
||||
if !from.privs.has(Priv::Admin) {
|
||||
ctx.notice(me, from.uid, "Access denied — STAFF needs the \x02admin\x02 privilege.");
|
||||
return;
|
||||
}
|
||||
if args.len() < 2 {
|
||||
ctx.notice(me, from.uid, "Syntax: STAFF <text>");
|
||||
return;
|
||||
}
|
||||
let text = args[1..].join(" ");
|
||||
// Config opers and runtime grants, resolved to canonical account names and
|
||||
// de-duplicated so nobody gets the memo twice.
|
||||
let mut names: Vec<String> = net.oper_accounts();
|
||||
names.extend(db.opers_list().into_iter().map(|(name, _, _)| name));
|
||||
let mut sent = 0usize;
|
||||
let mut seen: Vec<String> = Vec::new();
|
||||
for name in &names {
|
||||
let Some(canon) = db.resolve_account(name).map(str::to_string) else { continue };
|
||||
if seen.contains(&canon) {
|
||||
continue;
|
||||
}
|
||||
seen.push(canon.clone());
|
||||
if db.memo_send(&canon, account, &text, false).is_ok() {
|
||||
sent += 1;
|
||||
}
|
||||
}
|
||||
ctx.notice(me, from.uid, format!("Memo sent to \x02{sent}\x02 operator(s)."));
|
||||
}
|
||||
|
|
@ -283,6 +283,7 @@ impl Engine {
|
|||
|
||||
// Load the services-operator table (casefolded account -> privileges).
|
||||
pub fn set_opers(&mut self, opers: HashMap<String, Privs>) {
|
||||
self.network.set_config_opers(opers.keys().cloned().collect());
|
||||
self.opers = opers;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ pub struct Network {
|
|||
// Network-wide help index (service nick, blurb, per-command topics), built by
|
||||
// the engine at startup from every service so HelpServ can front it.
|
||||
pub help_catalog: Vec<(String, &'static str, &'static [HelpEntry])>,
|
||||
// Account names of the declarative config operators, mirrored from the engine
|
||||
// so services can enumerate staff (MemoServ STAFF). Runtime OPER grants live
|
||||
// in the store; a caller unions the two.
|
||||
config_opers: Vec<String>,
|
||||
}
|
||||
|
||||
// ChanFix scoring caps and rates.
|
||||
|
|
@ -106,6 +110,12 @@ impl Network {
|
|||
self.users.insert(uid.clone(), User { uid, nick, host, ip });
|
||||
}
|
||||
|
||||
// Mirror the engine's declarative config operators, so services can enumerate
|
||||
// staff. Called whenever the config oper set changes.
|
||||
pub fn set_config_opers(&mut self, accounts: Vec<String>) {
|
||||
self.config_opers = accounts;
|
||||
}
|
||||
|
||||
// Live sessions from `ip`.
|
||||
pub fn session_count(&self, ip: &str) -> u32 {
|
||||
self.sessions.get(ip).copied().unwrap_or(0)
|
||||
|
|
@ -368,6 +378,9 @@ impl Network {
|
|||
// The module-facing network view. Reads forward to Network's own accessors,
|
||||
// with the seen record projected into a plain view.
|
||||
impl NetView for Network {
|
||||
fn oper_accounts(&self) -> Vec<String> {
|
||||
self.config_opers.clone()
|
||||
}
|
||||
fn uid_by_nick(&self, nick: &str) -> Option<&str> {
|
||||
Network::uid_by_nick(self, nick)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -837,6 +837,38 @@
|
|||
assert_eq!(e.db.unread_memos("bob"), 1);
|
||||
}
|
||||
|
||||
// MemoServ STAFF memos every operator (config opers here), and only the
|
||||
// operators — a plain account gets nothing.
|
||||
#[test]
|
||||
fn memoserv_staff_memos_operators() {
|
||||
use echo_memoserv::MemoServ;
|
||||
use echo_nickserv::NickServ;
|
||||
let path = std::env::temp_dir().join("echo-msstaff.jsonl");
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let mut db = Db::open(&path, "42S");
|
||||
db.scram_iterations = 4096;
|
||||
db.register("boss", "pw", None).unwrap();
|
||||
db.register("mod", "pw", None).unwrap();
|
||||
db.register("alice", "pw", None).unwrap();
|
||||
let mut e = Engine::new(
|
||||
vec![
|
||||
Box::new(NickServ { uid: "42SAAAAAA".into(), guest_nick: "Guest".into(), guest_seq: 0 }),
|
||||
Box::new(MemoServ { uid: "42SAAAAAE".into() }),
|
||||
],
|
||||
db,
|
||||
);
|
||||
let mut opers = std::collections::HashMap::new();
|
||||
opers.insert("boss".to_string(), Privs::default().with(echo_api::Priv::Admin));
|
||||
opers.insert("mod".to_string(), Privs::default().with(echo_api::Priv::Admin));
|
||||
e.set_opers(opers);
|
||||
e.handle(NetEvent::UserConnect { uid: "000AAAAAB".into(), nick: "boss".into(), host: "h".into(), ip: "0.0.0.0".into() });
|
||||
e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAA".into(), text: "IDENTIFY pw".into() });
|
||||
let out = e.handle(NetEvent::Privmsg { from: "000AAAAAB".into(), to: "42SAAAAAE".into(), text: "STAFF heads up team".into() });
|
||||
assert!(out.iter().any(|a| matches!(a, NetAction::Notice { text, .. } if text.contains("2"))), "memoed 2 opers: {out:?}");
|
||||
assert_eq!(e.db.unread_memos("mod"), 1, "the other operator got it");
|
||||
assert_eq!(e.db.unread_memos("alice"), 0, "a non-operator did not");
|
||||
}
|
||||
|
||||
// NickServ SASET lets an operator edit another account's settings, and is
|
||||
// refused to non-operators.
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue