forbid: type the FORBID kind as an enum at the store boundary, string only in storage
All checks were successful
CI / check (push) Successful in 3m56s
All checks were successful
CI / check (push) Successful in 3m56s
This commit is contained in:
parent
1fb3615b7e
commit
2c8ba4460d
10 changed files with 91 additions and 49 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use echo_api::{ChanError, ChannelView, Priv, Store};
|
||||
use echo_api::{ChanError, ChannelView, ForbidKind, Priv, Store};
|
||||
use echo_api::{HelpEntry, Sender, Service, ServiceCtx};
|
||||
use echo_api::NetView;
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ impl Service for ChanServ {
|
|||
ctx.notice(me, from.uid, format!("You must be a channel operator (\x02@\x02) in \x02{chan}\x02 to register it."));
|
||||
return;
|
||||
}
|
||||
if let Some(reason) = db.is_forbidden("CHAN", chan) {
|
||||
if let Some(reason) = db.is_forbidden(ForbidKind::Chan, chan) {
|
||||
ctx.notice(me, from.uid, format!("\x02{chan}\x02 can't be registered: {reason}"));
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use echo_api::Store;
|
||||
use echo_api::{ForbidKind, Store};
|
||||
use echo_api::{Sender, ServiceCtx};
|
||||
|
||||
// SET PASSWORD <newpassword> | SET EMAIL [address]: change your account settings.
|
||||
|
|
@ -30,7 +30,7 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
|
|||
let email = args.get(2).map(|s| s.to_string());
|
||||
let cleared = email.is_none();
|
||||
if let Some(addr) = &email {
|
||||
if db.is_forbidden("EMAIL", addr).is_some() {
|
||||
if db.is_forbidden(ForbidKind::Email, addr).is_some() {
|
||||
ctx.notice(me, from.uid, "That email address is forbidden by network policy. Use a different one.");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use echo_api::{human_time, Priv, Sender, ServiceCtx, Store};
|
||||
use echo_api::{human_time, ForbidKind, Priv, Sender, ServiceCtx, Store};
|
||||
|
||||
// FORBID ADD <NICK|CHAN|EMAIL> <mask> <reason> | DEL <NICK|CHAN|EMAIL> <mask> | LIST
|
||||
// Bans a nick, channel, or email pattern from being registered. Admin-only.
|
||||
|
|
@ -9,7 +9,7 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
|
|||
}
|
||||
match args.get(1).map(|s| s.to_ascii_uppercase()).as_deref() {
|
||||
Some("ADD") => {
|
||||
let (Some(kind), Some(&mask)) = (args.get(2).and_then(|k| norm_kind(k)), args.get(3)) else {
|
||||
let (Some(kind), Some(&mask)) = (args.get(2).and_then(|k| ForbidKind::from_name(k)), args.get(3)) else {
|
||||
ctx.notice(me, from.uid, "Syntax: FORBID ADD <NICK|CHAN|EMAIL> <mask> <reason>");
|
||||
return;
|
||||
};
|
||||
|
|
@ -19,20 +19,22 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
|
|||
}
|
||||
let reason = args[4..].join(" ");
|
||||
let setter = from.account.unwrap_or(from.nick);
|
||||
let label = kind.wire().to_lowercase();
|
||||
match db.forbid_add(kind, mask, setter, &reason) {
|
||||
Ok(true) => ctx.notice(me, from.uid, format!("Forbade {} \x02{mask}\x02.", kind.to_lowercase())),
|
||||
Ok(false) => ctx.notice(me, from.uid, format!("Updated the forbid on {} \x02{mask}\x02.", kind.to_lowercase())),
|
||||
Ok(true) => ctx.notice(me, from.uid, format!("Forbade {label} \x02{mask}\x02.")),
|
||||
Ok(false) => ctx.notice(me, from.uid, format!("Updated the forbid on {label} \x02{mask}\x02.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
}
|
||||
Some("DEL") | Some("REMOVE") => {
|
||||
let (Some(kind), Some(&mask)) = (args.get(2).and_then(|k| norm_kind(k)), args.get(3)) else {
|
||||
let (Some(kind), Some(&mask)) = (args.get(2).and_then(|k| ForbidKind::from_name(k)), args.get(3)) else {
|
||||
ctx.notice(me, from.uid, "Syntax: FORBID DEL <NICK|CHAN|EMAIL> <mask>");
|
||||
return;
|
||||
};
|
||||
let label = kind.wire().to_lowercase();
|
||||
match db.forbid_del(kind, mask) {
|
||||
Ok(true) => ctx.notice(me, from.uid, format!("Removed the forbid on {} \x02{mask}\x02.", kind.to_lowercase())),
|
||||
Ok(false) => ctx.notice(me, from.uid, format!("No forbid on {} \x02{mask}\x02.", kind.to_lowercase())),
|
||||
Ok(true) => ctx.notice(me, from.uid, format!("Removed the forbid on {label} \x02{mask}\x02.")),
|
||||
Ok(false) => ctx.notice(me, from.uid, format!("No forbid on {label} \x02{mask}\x02.")),
|
||||
Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."),
|
||||
}
|
||||
}
|
||||
|
|
@ -44,19 +46,9 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db:
|
|||
}
|
||||
ctx.notice(me, from.uid, "Registration bans:");
|
||||
for f in &forbids {
|
||||
ctx.notice(me, from.uid, format!(" [{}] \x02{}\x02 by {} ({}) — {}", f.kind, f.mask, f.setter, human_time(f.ts), f.reason));
|
||||
ctx.notice(me, from.uid, format!(" [{}] \x02{}\x02 by {} ({}) — {}", f.kind.wire(), f.mask, f.setter, human_time(f.ts), f.reason));
|
||||
}
|
||||
}
|
||||
_ => ctx.notice(me, from.uid, "Syntax: FORBID ADD <NICK|CHAN|EMAIL> <mask> <reason> | DEL <NICK|CHAN|EMAIL> <mask> | LIST"),
|
||||
}
|
||||
}
|
||||
|
||||
// Canonicalise the kind argument to NICK / CHAN / EMAIL.
|
||||
fn norm_kind(k: &str) -> Option<&'static str> {
|
||||
match k.to_ascii_uppercase().as_str() {
|
||||
"NICK" | "NICKNAME" | "ACCOUNT" => Some("NICK"),
|
||||
"CHAN" | "CHANNEL" => Some("CHAN"),
|
||||
"EMAIL" | "MAIL" => Some("EMAIL"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue