OperServ: INFO staff notes on accounts and channels
INFO ADD <target> <note> / DEL <target> / <target> attaches a staff note to an account or channel (a #name is a channel, else an account). The note is shown in that service's INFO — but to operators only (Priv::Auspex), never to the account's own owner. Admin-only to set. Follows the typed-field-on-the-entity pattern: an oper_note field folded through AccountOperNoteSet (Global) / ChannelOperNoteSet (Local) events, read via dedicated Store getters so it stays out of the public views and the directory feed.
This commit is contained in:
parent
8ccc9fa8ea
commit
51d4ebf789
8 changed files with 216 additions and 9 deletions
|
|
@ -713,6 +713,11 @@ pub trait Store {
|
|||
fn ignore_add(&mut self, mask: &str, reason: &str, expires: Option<u64>);
|
||||
fn ignore_del(&mut self, mask: &str) -> bool;
|
||||
fn ignores(&self) -> Vec<IgnoreView>;
|
||||
// Staff notes on accounts/channels (oper-only), shown in INFO to operators.
|
||||
fn set_account_note(&mut self, account: &str, note: Option<String>) -> bool;
|
||||
fn account_note(&self, account: &str) -> Option<String>;
|
||||
fn set_channel_note(&mut self, channel: &str, note: Option<String>) -> bool;
|
||||
fn channel_note(&self, channel: &str) -> Option<String>;
|
||||
fn register_channel(&mut self, name: &str, founder: &str) -> Result<(), ChanError>;
|
||||
fn drop_channel(&mut self, name: &str) -> Result<(), ChanError>;
|
||||
fn set_mlock(&mut self, name: &str, on: &str, off: &str) -> Result<(), ChanError>;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use fedserv_api::{ChanError, ChannelView, Store};
|
||||
use fedserv_api::{ChanError, ChannelView, Priv, Store};
|
||||
use fedserv_api::{Sender, Service, ServiceCtx};
|
||||
use fedserv_api::NetView;
|
||||
|
||||
|
|
@ -118,6 +118,12 @@ impl Service for ChanServ {
|
|||
if !opts.is_empty() {
|
||||
ctx.notice(me, from.uid, format!(" Options : {}", opts.join(", ")));
|
||||
}
|
||||
// A staff note is shown to operators only.
|
||||
if from.privs.has(Priv::Auspex) {
|
||||
if let Some(note) = db.channel_note(chan) {
|
||||
ctx.notice(me, from.uid, format!(" Staff note : {note}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
None => ctx.notice(me, from.uid, format!("\x02{chan}\x02 isn't registered.")),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,4 +31,10 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
|
|||
ctx.notice(me, from.uid, format!(" Auto-join : {} channel(s) — see \x02AJOIN LIST\x02", ajoin.len()));
|
||||
}
|
||||
}
|
||||
// A staff note is for operators' eyes only, never the account's owner.
|
||||
if from.privs.has(Priv::Auspex) {
|
||||
if let Some(note) = db.account_note(&acct.name) {
|
||||
ctx.notice(me, from.uid, format!(" Staff note : {note}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
53
operserv/src/info.rs
Normal file
53
operserv/src/info.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
use fedserv_api::{Priv, Sender, ServiceCtx, Store};
|
||||
|
||||
// INFO <target> | INFO ADD <target> <note> | INFO DEL <target>: attach a staff
|
||||
// note to an account or channel (a `#name` is a channel, else an account). The
|
||||
// note is shown to operators in that service's INFO. Admin-only.
|
||||
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
if !from.privs.has(Priv::Admin) {
|
||||
ctx.notice(me, from.uid, "Access denied — INFO needs the \x02admin\x02 privilege.");
|
||||
return;
|
||||
}
|
||||
match args.get(1).map(|s| s.to_ascii_uppercase()).as_deref() {
|
||||
Some("ADD") | Some("SET") => set(me, from, args.get(2).copied(), args.get(3..).unwrap_or(&[]), ctx, db),
|
||||
Some("DEL") | Some("CLEAR") => set(me, from, args.get(2).copied(), &[], ctx, db),
|
||||
Some(_) => show(me, from, args[1], ctx, db),
|
||||
None => ctx.notice(me, from.uid, "Syntax: INFO <target> | INFO ADD <target> <note> | INFO DEL <target>"),
|
||||
}
|
||||
}
|
||||
|
||||
// `note` empty clears; otherwise it's the joined note words.
|
||||
fn set(me: &str, from: &Sender, target: Option<&str>, note: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
let Some(target) = target else {
|
||||
ctx.notice(me, from.uid, "Syntax: INFO ADD <target> <note> | INFO DEL <target>");
|
||||
return;
|
||||
};
|
||||
let text = note.join(" ");
|
||||
let value = if text.trim().is_empty() { None } else { Some(text) };
|
||||
let (ok, kind) = if target.starts_with('#') || target.starts_with('&') {
|
||||
(db.set_channel_note(target, value.clone()), "channel")
|
||||
} else if let Some(account) = db.resolve_account(target).map(str::to_string) {
|
||||
(db.set_account_note(&account, value.clone()), "account")
|
||||
} else {
|
||||
(false, "account")
|
||||
};
|
||||
if !ok {
|
||||
ctx.notice(me, from.uid, format!("There's no {kind} \x02{target}\x02."));
|
||||
} else if value.is_some() {
|
||||
ctx.notice(me, from.uid, format!("Staff note set on \x02{target}\x02."));
|
||||
} else {
|
||||
ctx.notice(me, from.uid, format!("Staff note on \x02{target}\x02 cleared."));
|
||||
}
|
||||
}
|
||||
|
||||
fn show(me: &str, from: &Sender, target: &str, ctx: &mut ServiceCtx, db: &mut dyn Store) {
|
||||
let note = if target.starts_with('#') || target.starts_with('&') {
|
||||
db.channel_note(target)
|
||||
} else {
|
||||
db.resolve_account(target).map(str::to_string).and_then(|a| db.account_note(&a))
|
||||
};
|
||||
match note {
|
||||
Some(n) => ctx.notice(me, from.uid, format!("Staff note on \x02{target}\x02: {n}")),
|
||||
None => ctx.notice(me, from.uid, format!("No staff note on \x02{target}\x02.")),
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,8 @@ mod ignore;
|
|||
mod stats;
|
||||
#[path = "svs.rs"]
|
||||
mod svs;
|
||||
#[path = "info.rs"]
|
||||
mod info;
|
||||
|
||||
pub struct OperServ {
|
||||
pub uid: String,
|
||||
|
|
@ -55,6 +57,7 @@ impl Service for OperServ {
|
|||
Some(cmd) if cmd.eq_ignore_ascii_case("STATS") => stats::handle(me, from, db, ctx),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("SVSNICK") => svs::nick(me, from, args, ctx, net),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("SVSJOIN") => svs::join(me, from, args, ctx, net),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("INFO") => info::handle(me, from, args, ctx, db),
|
||||
Some(cmd) if cmd.eq_ignore_ascii_case("HELP") => help(me, from, ctx),
|
||||
None => help(me, from, ctx),
|
||||
Some(other) => ctx.notice(me, from.uid, format!("I don't know \x02{other}\x02. Try \x02HELP\x02.")),
|
||||
|
|
@ -63,5 +66,5 @@ impl Service for OperServ {
|
|||
}
|
||||
|
||||
fn help(me: &str, from: &Sender, ctx: &mut ServiceCtx) {
|
||||
ctx.notice(me, from.uid, "OperServ holds network operator tools (Priv::Admin): \x02AKILL\x02 ADD|DEL|LIST (user@host bans), \x02SQLINE\x02 ADD|DEL|LIST (nick bans), \x02GLOBAL\x02 <message> (announce to everyone), \x02KILL\x02 <nick> [reason] (disconnect a user), \x02KICK\x02 <#chan> <nick> [reason], \x02MODE\x02 <#chan> <modes> [params], \x02IGNORE\x02 ADD|DEL|LIST (silence a user from services), \x02STATS\x02 (enforcement overview), \x02SVSNICK\x02 <nick> <newnick>, \x02SVSJOIN\x02 <nick> <#chan> [key].");
|
||||
ctx.notice(me, from.uid, "OperServ holds network operator tools (Priv::Admin): \x02AKILL\x02 ADD|DEL|LIST (user@host bans), \x02SQLINE\x02 ADD|DEL|LIST (nick bans), \x02GLOBAL\x02 <message> (announce to everyone), \x02KILL\x02 <nick> [reason] (disconnect a user), \x02KICK\x02 <#chan> <nick> [reason], \x02MODE\x02 <#chan> <modes> [params], \x02IGNORE\x02 ADD|DEL|LIST (silence a user from services), \x02STATS\x02 (enforcement overview), \x02SVSNICK\x02 <nick> <newnick>, \x02SVSJOIN\x02 <nick> <#chan> [key], \x02INFO\x02 ADD|DEL <target> (staff notes).");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,9 @@ pub struct Account {
|
|||
// the next activity, so each idle spell warns at most once).
|
||||
#[serde(default)]
|
||||
pub expiry_warned: bool,
|
||||
// A staff note (OperServ INFO), shown only to operators.
|
||||
#[serde(default)]
|
||||
pub oper_note: Option<String>,
|
||||
}
|
||||
|
||||
// A requested vhost awaiting approval.
|
||||
|
|
@ -179,6 +182,9 @@ pub enum Event {
|
|||
// An impending-expiry warning email was sent; cleared by the next Seen/Used.
|
||||
AccountExpiryWarned { account: String },
|
||||
ChannelExpiryWarned { channel: String },
|
||||
// A staff note set or cleared (OperServ INFO).
|
||||
AccountOperNoteSet { account: String, note: Option<String> },
|
||||
ChannelOperNoteSet { channel: String, note: Option<String> },
|
||||
// Network bans (OperServ AKILL / SQLINE). Global: a ban covers the whole
|
||||
// network, so every node holds the list and re-applies it at burst. `kind`
|
||||
// is the ircd X-line type and defaults to "G" for records predating it.
|
||||
|
|
@ -235,6 +241,7 @@ impl Event {
|
|||
| Event::AccountSeen { .. }
|
||||
| Event::AccountNoExpire { .. }
|
||||
| Event::AccountExpiryWarned { .. }
|
||||
| Event::AccountOperNoteSet { .. }
|
||||
| Event::AkillAdded { .. }
|
||||
| Event::AkillRemoved { .. } => Scope::Global,
|
||||
Event::ChannelRegistered { .. }
|
||||
|
|
@ -265,7 +272,8 @@ impl Event {
|
|||
| Event::VhostTemplateSet { .. }
|
||||
| Event::ChannelUsed { .. }
|
||||
| Event::ChannelNoExpire { .. }
|
||||
| Event::ChannelExpiryWarned { .. } => Scope::Local,
|
||||
| Event::ChannelExpiryWarned { .. }
|
||||
| Event::ChannelOperNoteSet { .. } => Scope::Local,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -444,6 +452,9 @@ pub struct ChannelInfo {
|
|||
// Whether an impending-expiry warning email has already been sent.
|
||||
#[serde(default)]
|
||||
pub expiry_warned: bool,
|
||||
// A staff note (OperServ INFO), shown only to operators.
|
||||
#[serde(default)]
|
||||
pub oper_note: Option<String>,
|
||||
}
|
||||
|
||||
// A bot auto-response: when a channel line matches `pattern`, the assigned bot
|
||||
|
|
@ -1018,6 +1029,9 @@ impl Db {
|
|||
if !c.triggers.is_empty() {
|
||||
snapshot.push(Event::ChannelTriggersSet { channel: c.name.clone(), triggers: c.triggers.clone() });
|
||||
}
|
||||
if let Some(note) = &c.oper_note {
|
||||
snapshot.push(Event::ChannelOperNoteSet { channel: c.name.clone(), note: Some(note.clone()) });
|
||||
}
|
||||
}
|
||||
for (nick, account) in &self.grouped {
|
||||
snapshot.push(Event::NickGrouped { nick: nick.clone(), account: account.clone() });
|
||||
|
|
@ -1158,6 +1172,7 @@ impl Db {
|
|||
last_seen: now(),
|
||||
noexpire: false,
|
||||
expiry_warned: false,
|
||||
oper_note: None,
|
||||
};
|
||||
self.log.append(Event::AccountRegistered(Box::new(account.clone()))).map_err(|_| RegError::Internal)?;
|
||||
self.accounts.insert(key(name), account);
|
||||
|
|
@ -1772,6 +1787,38 @@ impl Db {
|
|||
}
|
||||
}
|
||||
|
||||
/// Set or clear an account's staff note. Returns whether the account exists.
|
||||
pub fn set_account_note(&mut self, account: &str, note: Option<String>) -> bool {
|
||||
let k = key(account);
|
||||
if !self.accounts.contains_key(&k) {
|
||||
return false;
|
||||
}
|
||||
let _ = self.log.append(Event::AccountOperNoteSet { account: account.to_string(), note: note.clone() });
|
||||
self.accounts.get_mut(&k).unwrap().oper_note = note;
|
||||
true
|
||||
}
|
||||
|
||||
/// An account's staff note, if any.
|
||||
pub fn account_note(&self, account: &str) -> Option<String> {
|
||||
self.accounts.get(&key(account)).and_then(|a| a.oper_note.clone())
|
||||
}
|
||||
|
||||
/// Set or clear a channel's staff note. Returns whether the channel exists.
|
||||
pub fn set_channel_note(&mut self, channel: &str, note: Option<String>) -> bool {
|
||||
let k = key(channel);
|
||||
if !self.channels.contains_key(&k) {
|
||||
return false;
|
||||
}
|
||||
let _ = self.log.append(Event::ChannelOperNoteSet { channel: channel.to_string(), note: note.clone() });
|
||||
self.channels.get_mut(&k).unwrap().oper_note = note;
|
||||
true
|
||||
}
|
||||
|
||||
/// A channel's staff note, if any.
|
||||
pub fn channel_note(&self, channel: &str) -> Option<String> {
|
||||
self.channels.get(&key(channel)).and_then(|c| c.oper_note.clone())
|
||||
}
|
||||
|
||||
/// Add (or refresh) a `kind` network ban. Returns whether it was newly added.
|
||||
pub fn akill_add(&mut self, kind: &str, mask: &str, setter: &str, reason: &str, expires: Option<u64>) -> Result<bool, RegError> {
|
||||
let same = |a: &Akill| a.kind == kind && a.mask.eq_ignore_ascii_case(mask);
|
||||
|
|
@ -1866,7 +1913,7 @@ impl Db {
|
|||
self.log
|
||||
.append(Event::ChannelRegistered { name: name.to_string(), founder: founder.to_string(), ts })
|
||||
.map_err(|_| ChanError::Internal)?;
|
||||
self.channels.insert(k, ChannelInfo { name: name.to_string(), founder: founder.to_string(), ts, lock_on: String::new(), lock_off: String::new(), access: Vec::new(), akick: Vec::new(), desc: String::new(), entrymsg: String::new(), settings: ChanSettings::default(), topic: String::new(), suspension: None, assigned_bot: None , kickers: KickerSettings::default() , badwords: Vec::new(), badwords_rev: 0 , triggers: Vec::new(), triggers_rev: 0, last_used: ts, noexpire: false, expiry_warned: false });
|
||||
self.channels.insert(k, ChannelInfo { name: name.to_string(), founder: founder.to_string(), ts, lock_on: String::new(), lock_off: String::new(), access: Vec::new(), akick: Vec::new(), desc: String::new(), entrymsg: String::new(), settings: ChanSettings::default(), topic: String::new(), suspension: None, assigned_bot: None , kickers: KickerSettings::default() , badwords: Vec::new(), badwords_rev: 0 , triggers: Vec::new(), triggers_rev: 0, last_used: ts, noexpire: false, expiry_warned: false, oper_note: None });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -2604,7 +2651,7 @@ fn apply(accounts: &mut HashMap<String, Account>, channels: &mut HashMap<String,
|
|||
grouped.remove(&key(&nick));
|
||||
}
|
||||
Event::ChannelRegistered { name, founder, ts } => {
|
||||
channels.insert(key(&name), ChannelInfo { name, founder, ts, lock_on: String::new(), lock_off: String::new(), access: Vec::new(), akick: Vec::new(), desc: String::new(), entrymsg: String::new(), settings: ChanSettings::default(), topic: String::new(), suspension: None, assigned_bot: None , kickers: KickerSettings::default() , badwords: Vec::new(), badwords_rev: 0 , triggers: Vec::new(), triggers_rev: 0, last_used: ts, noexpire: false, expiry_warned: false });
|
||||
channels.insert(key(&name), ChannelInfo { name, founder, ts, lock_on: String::new(), lock_off: String::new(), access: Vec::new(), akick: Vec::new(), desc: String::new(), entrymsg: String::new(), settings: ChanSettings::default(), topic: String::new(), suspension: None, assigned_bot: None , kickers: KickerSettings::default() , badwords: Vec::new(), badwords_rev: 0 , triggers: Vec::new(), triggers_rev: 0, last_used: ts, noexpire: false, expiry_warned: false, oper_note: None });
|
||||
}
|
||||
Event::ChannelDropped { name } => {
|
||||
channels.remove(&key(&name));
|
||||
|
|
@ -2765,6 +2812,16 @@ fn apply(accounts: &mut HashMap<String, Account>, channels: &mut HashMap<String,
|
|||
c.expiry_warned = true;
|
||||
}
|
||||
}
|
||||
Event::AccountOperNoteSet { account, note } => {
|
||||
if let Some(a) = accounts.get_mut(&key(&account)) {
|
||||
a.oper_note = note;
|
||||
}
|
||||
}
|
||||
Event::ChannelOperNoteSet { channel, note } => {
|
||||
if let Some(c) = channels.get_mut(&key(&channel)) {
|
||||
c.oper_note = note;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3015,6 +3072,18 @@ impl Store for Db {
|
|||
fn ignores(&self) -> Vec<IgnoreView> {
|
||||
Db::ignores(self)
|
||||
}
|
||||
fn set_account_note(&mut self, account: &str, note: Option<String>) -> bool {
|
||||
Db::set_account_note(self, account, note)
|
||||
}
|
||||
fn account_note(&self, account: &str) -> Option<String> {
|
||||
Db::account_note(self, account)
|
||||
}
|
||||
fn set_channel_note(&mut self, channel: &str, note: Option<String>) -> bool {
|
||||
Db::set_channel_note(self, channel, note)
|
||||
}
|
||||
fn channel_note(&self, channel: &str) -> Option<String> {
|
||||
Db::channel_note(self, channel)
|
||||
}
|
||||
fn register_channel(&mut self, name: &str, founder: &str) -> Result<(), ChanError> {
|
||||
Db::register_channel(self, name, founder)
|
||||
}
|
||||
|
|
@ -3215,7 +3284,7 @@ mod tests {
|
|||
fn account_conflict_resolves_deterministically() {
|
||||
let alice = |hash: &str, ts: u64, home: &str| Account {
|
||||
name: "alice".into(), password_hash: hash.into(), email: None,
|
||||
ts, home: home.into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], greet: String::new(), vhost: None, vhost_request: None, last_seen: ts, noexpire: false, expiry_warned: false,
|
||||
ts, home: home.into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], greet: String::new(), vhost: None, vhost_request: None, last_seen: ts, noexpire: false, expiry_warned: false, oper_note: None,
|
||||
};
|
||||
let converge = |first: &Account, second: &Account| {
|
||||
let (mut acc, mut ch, mut gr, mut bo, mut hc, mut ak) = (HashMap::new(), HashMap::new(), HashMap::new(), HashMap::new(), HostConfig::default(), Vec::new());
|
||||
|
|
@ -3491,7 +3560,7 @@ mod tests {
|
|||
db.register("alice", "pw", None).unwrap();
|
||||
let bob = Account {
|
||||
name: "bob".into(), password_hash: "x".into(), email: None,
|
||||
ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], greet: String::new(), vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false,
|
||||
ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], greet: String::new(), vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false, oper_note: None,
|
||||
};
|
||||
let entry = LogEntry { origin: "peer".into(), seq: 0, lamport: 1, event: Event::AccountRegistered(Box::new(bob)) };
|
||||
db.ingest(entry).unwrap();
|
||||
|
|
|
|||
|
|
@ -1574,6 +1574,14 @@ fn audit_summary(event: &db::Event) -> Option<String> {
|
|||
format!("set a {} on \x02{mask}\x02{temp} ({reason})", ban_kind_label(kind))
|
||||
}
|
||||
AkillRemoved { kind, mask } => format!("lifted the {} on \x02{mask}\x02", ban_kind_label(kind)),
|
||||
AccountOperNoteSet { account, note } => match note {
|
||||
Some(_) => format!("set a staff note on \x02{account}\x02"),
|
||||
None => format!("cleared the staff note on \x02{account}\x02"),
|
||||
},
|
||||
ChannelOperNoteSet { channel, note } => match note {
|
||||
Some(_) => format!("set a staff note on \x02{channel}\x02"),
|
||||
None => format!("cleared the staff note on \x02{channel}\x02"),
|
||||
},
|
||||
AccountNoExpire { account, on } => {
|
||||
let verb = if *on { "pinned" } else { "unpinned" };
|
||||
format!("{verb} account \x02{account}\x02 against expiry")
|
||||
|
|
@ -2148,7 +2156,7 @@ mod tests {
|
|||
// An earlier claim from another node wins and takes the name over.
|
||||
let winner = db::Account {
|
||||
name: "alice".into(), password_hash: "OTHER".into(), email: None,
|
||||
ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], greet: String::new(), vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false,
|
||||
ts: 0, home: "peer".into(), scram256: None, scram512: None, certfps: vec![], verified: true, ajoin: vec![], suspension: None, memos: vec![], greet: String::new(), vhost: None, vhost_request: None, last_seen: 0, noexpire: false, expiry_warned: false, oper_note: None,
|
||||
};
|
||||
let entry = LogEntry::for_test("peer", 0, 1, db::Event::AccountRegistered(Box::new(winner)));
|
||||
e.gossip_ingest(entry).unwrap();
|
||||
|
|
@ -4016,6 +4024,60 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
// OperServ INFO staff notes: an admin annotates an account/channel; the note
|
||||
// shows in that service's INFO to opers only, never to the account owner.
|
||||
#[test]
|
||||
fn operserv_info_staff_notes() {
|
||||
use fedserv_chanserv::ChanServ;
|
||||
use fedserv_operserv::OperServ;
|
||||
let path = std::env::temp_dir().join("fedserv-osinfo.jsonl");
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let mut db = Db::open(&path, "42S");
|
||||
db.scram_iterations = 4096;
|
||||
db.register("staff", "password1", None).unwrap();
|
||||
db.register("alice", "password1", None).unwrap();
|
||||
db.register_channel("#room", "staff").unwrap();
|
||||
let mut e = Engine::new(
|
||||
vec![
|
||||
Box::new(NickServ { uid: "42SAAAAAA".into(), guest_nick: "Guest".into(), guest_seq: 0 }),
|
||||
Box::new(ChanServ { uid: "42SAAAAAB".into() }),
|
||||
Box::new(OperServ { uid: "42SAAAAAH".into() }),
|
||||
],
|
||||
db,
|
||||
);
|
||||
e.set_sid("42S".into());
|
||||
let mut opers = std::collections::HashMap::new();
|
||||
opers.insert("staff".to_string(), Privs::default().with(fedserv_api::Priv::Admin).with(fedserv_api::Priv::Auspex));
|
||||
e.set_opers(opers);
|
||||
let os = |e: &mut Engine, uid: &str, t: &str| e.handle(NetEvent::Privmsg { from: uid.into(), to: "42SAAAAAH".into(), text: t.into() });
|
||||
let ns = |e: &mut Engine, uid: &str, t: &str| e.handle(NetEvent::Privmsg { from: uid.into(), to: "42SAAAAAA".into(), text: t.into() });
|
||||
let cs = |e: &mut Engine, uid: &str, t: &str| e.handle(NetEvent::Privmsg { from: uid.into(), to: "42SAAAAAB".into(), text: t.into() });
|
||||
let has = |out: &[NetAction], needle: &str| out.iter().any(|a| matches!(a, NetAction::Notice { text, .. } if text.contains(needle)));
|
||||
|
||||
e.handle(NetEvent::UserConnect { uid: "000AAAAAS".into(), nick: "staff".into(), host: "h".into() });
|
||||
e.handle(NetEvent::Privmsg { from: "000AAAAAS".into(), to: "42SAAAAAA".into(), text: "IDENTIFY password1".into() });
|
||||
e.handle(NetEvent::UserConnect { uid: "000AAAAAL".into(), nick: "alice".into(), host: "h".into() });
|
||||
e.handle(NetEvent::Privmsg { from: "000AAAAAL".into(), to: "42SAAAAAA".into(), text: "IDENTIFY password1".into() });
|
||||
|
||||
// Admin attaches a note; it shows in NickServ INFO to the oper.
|
||||
os(&mut e, "000AAAAAS", "INFO ADD alice known troublemaker");
|
||||
assert!(has(&ns(&mut e, "000AAAAAS", "INFO alice"), "known troublemaker"), "note shown to oper in NS INFO");
|
||||
assert!(has(&os(&mut e, "000AAAAAS", "INFO alice"), "known troublemaker"), "note shown via OperServ INFO");
|
||||
// The account's own owner never sees the staff note.
|
||||
assert!(!has(&ns(&mut e, "000AAAAAL", "INFO alice"), "Staff note"), "owner doesn't see the note");
|
||||
|
||||
// Channel notes show in ChanServ INFO to the oper.
|
||||
os(&mut e, "000AAAAAS", "INFO ADD #room watch for drama");
|
||||
assert!(has(&cs(&mut e, "000AAAAAS", "INFO #room"), "watch for drama"), "channel note in CS INFO");
|
||||
|
||||
// DEL clears it.
|
||||
os(&mut e, "000AAAAAS", "INFO DEL alice");
|
||||
assert!(!has(&ns(&mut e, "000AAAAAS", "INFO alice"), "Staff note"), "note cleared");
|
||||
|
||||
// A non-admin can't set notes.
|
||||
assert!(has(&os(&mut e, "000AAAAAL", "INFO ADD staff x"), "Access denied"), "non-admin refused");
|
||||
}
|
||||
|
||||
// OperServ SVSNICK / SVSJOIN: force a user's nick or channel join, admin-gated.
|
||||
#[test]
|
||||
fn operserv_svs_forces_nick_and_join() {
|
||||
|
|
|
|||
|
|
@ -168,7 +168,9 @@ fn to_wire(entry: &LogEntry) -> Option<ReplicationEvent> {
|
|||
| Event::AkillAdded { .. }
|
||||
| Event::AkillRemoved { .. }
|
||||
| Event::AccountExpiryWarned { .. }
|
||||
| Event::ChannelExpiryWarned { .. } => return None,
|
||||
| Event::ChannelExpiryWarned { .. }
|
||||
| Event::AccountOperNoteSet { .. }
|
||||
| Event::ChannelOperNoteSet { .. } => return None,
|
||||
};
|
||||
Some(ReplicationEvent { origin: entry.origin().to_string(), seq: entry.seq(), lamport: entry.lamport(), kind: Some(kind) })
|
||||
}
|
||||
|
|
@ -428,6 +430,7 @@ mod tests {
|
|||
last_seen: 111,
|
||||
noexpire: false,
|
||||
expiry_warned: false,
|
||||
oper_note: None,
|
||||
};
|
||||
let registered = LogEntry::for_test("A", 0, 1, Event::AccountRegistered(Box::new(acct)));
|
||||
let wire = to_wire(®istered).expect("account registration replicates");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue