diff --git a/modules/chanserv/src/access.rs b/modules/chanserv/src/access.rs index 90ed47f..ea70a14 100644 --- a/modules/chanserv/src/access.rs +++ b/modules/chanserv/src/access.rs @@ -4,7 +4,7 @@ use echo_api::{Sender, ServiceCtx}; // ACCESS <#channel> LIST | ADD | DEL pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) { let Some(&chan) = args.get(1) else { - ctx.notice(me, from.uid, "Syntax: ACCESS <#channel> LIST | ADD | DEL "); + ctx.notice(me, from.uid, "Syntax: ACCESS <#channel> LIST | ADD | DEL "); return; }; match args.get(2).map(|s| s.to_ascii_uppercase()).as_deref() { @@ -50,7 +50,7 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: Err(_) => ctx.notice(me, from.uid, "Sorry, that didn't work. Please try again in a moment."), } } - _ => ctx.notice(me, from.uid, "Syntax: ACCESS <#channel> LIST | ADD | DEL "), + _ => ctx.notice(me, from.uid, "Syntax: ACCESS <#channel> LIST | ADD | DEL "), } } diff --git a/modules/chanserv/src/lib.rs b/modules/chanserv/src/lib.rs index 868307a..ec0982f 100644 --- a/modules/chanserv/src/lib.rs +++ b/modules/chanserv/src/lib.rs @@ -52,7 +52,7 @@ const TOPICS: &[HelpEntry] = &[ HelpEntry { cmd: "INFO", summary: "show channel information", detail: "Syntax: \x02INFO <#channel>\x02\nShows a channel's registration and settings." }, HelpEntry { cmd: "LIST", summary: "list registered channels", detail: "Syntax: \x02LIST\x02\nLists registered channels." }, HelpEntry { cmd: "SET", summary: "change founder or settings", detail: "Syntax: \x02SET <#channel> FOUNDER | DESC | URL [address] | EMAIL [address] | SUCCESSOR |OFF | SIGNKICK|PRIVATE|PEACE|SECUREOPS|RESTRICTED|AUTOOP|KEEPTOPIC|TOPICLOCK {ON|OFF}\x02\nTransfers the founder or changes a channel setting." }, - HelpEntry { cmd: "ACCESS", summary: "manage the access list", detail: "Syntax: \x02ACCESS <#channel> LIST | ADD | DEL \x02\nManages the channel access list." }, + HelpEntry { cmd: "ACCESS", summary: "manage the access list", detail: "Syntax: \x02ACCESS <#channel> LIST | ADD | DEL \x02\nManages the channel access list. The target may be a GroupServ \x02!group\x02; each of its members holding the group's \x02c\x02 flag then inherits the access." }, HelpEntry { cmd: "FLAGS", summary: "granular per-account flags", detail: "Syntax: \x02FLAGS <#channel> [account [+/-flags]]\x02\nViews or changes granular per-account channel flags." }, HelpEntry { cmd: "AOP/SOP/VOP", summary: "tiered access shortcuts", detail: "Syntax: \x02AOP|SOP|VOP <#channel> ADD | DEL | LIST\x02\nTiered shortcuts over ACCESS: AOP and SOP grant op, VOP grants voice." }, HelpEntry { cmd: "STATUS", summary: "show a user's access", detail: "Syntax: \x02STATUS <#channel> [nick]\x02\nShows a user's access level on a channel." }, diff --git a/modules/groupserv/src/lib.rs b/modules/groupserv/src/lib.rs index 9d25639..29a7f0e 100644 --- a/modules/groupserv/src/lib.rs +++ b/modules/groupserv/src/lib.rs @@ -25,16 +25,16 @@ mod del; #[path = "flags.rs"] mod flags; -const BLURB: &str = "GroupServ manages user groups: a \x02!name\x02 owning member accounts. A channel can grant access to a group, and every member then inherits it."; +const BLURB: &str = "GroupServ manages user groups: a \x02!name\x02 owning member accounts. Add a group to a channel's access (\x02/msg ChanServ ACCESS #chan ADD !name op\x02) and each member holding the group's \x02c\x02 flag inherits it."; const TOPICS: &[HelpEntry] = &[ HelpEntry { cmd: "REGISTER", summary: "create a group you found", detail: "Syntax: \x02REGISTER \x02\nCreates a group with you as founder. A group name starts with '!', e.g. !staff." }, HelpEntry { cmd: "DROP", summary: "delete a group you founded", detail: "Syntax: \x02DROP \x02\nDeletes a group. Founder only." }, HelpEntry { cmd: "INFO", summary: "show a group's founder and size", detail: "Syntax: \x02INFO \x02\nShows a group's founder and member count." }, HelpEntry { cmd: "LIST", summary: "list groups you belong to", detail: "Syntax: \x02LIST\x02\nLists the groups you belong to. Operators see every group." }, - HelpEntry { cmd: "ADD", summary: "add a member", detail: "Syntax: \x02ADD \x02\nAdds a plain member. Needs the founder or the 'f' flag." }, + HelpEntry { cmd: "ADD", summary: "add a member", detail: "Syntax: \x02ADD \x02\nAdds a plain member (no flags). To let them inherit the group's channel access, give them the \x02c\x02 flag with FLAGS. Needs the founder or the 'f' flag." }, HelpEntry { cmd: "DEL", summary: "remove a member", detail: "Syntax: \x02DEL \x02\nRemoves a member. Needs the founder or the 'f' flag." }, - HelpEntry { cmd: "FLAGS", summary: "view or change group flags", detail: "Syntax: \x02FLAGS [account [+/-flags]]\x02\nLists, shows, or changes group-access flags (F founder, f manage, i invite, c channel-access, s set, m memo). Changing needs the founder or the 'f' flag." }, + HelpEntry { cmd: "FLAGS", summary: "view or change group flags", detail: "Syntax: \x02FLAGS [account [+/-flags]]\x02\nLists, shows, or changes group-access flags (F founder, f manage, i invite, c inherit the group's channel access, s set, m memo). Changing needs the founder or the 'f' flag." }, ]; pub struct GroupServ { diff --git a/src/engine/db/network.rs b/src/engine/db/network.rs index 1a0465c..3cbf172 100644 --- a/src/engine/db/network.rs +++ b/src/engine/db/network.rs @@ -478,9 +478,15 @@ impl Db { } /// Whether an account is in a group (its founder or a member). - pub fn is_group_member(&self, name: &str, account: &str) -> bool { + // Whether `account` inherits a group's channel access (when the group is on a + // channel's access list): the group's founder, or a member holding the 'c' + // (channel-access) flag. Plain membership is not enough — the flag gates it. + fn group_grants_channel_access(&self, name: &str, account: &str) -> bool { let k = key(name); - self.net.groups.iter().find(|g| key(&g.name) == k).is_some_and(|g| g.founder.eq_ignore_ascii_case(account) || g.members.iter().any(|m| m.account.eq_ignore_ascii_case(account))) + self.net.groups.iter().find(|g| key(&g.name) == k).is_some_and(|g| { + g.founder.eq_ignore_ascii_case(account) + || g.members.iter().any(|m| m.account.eq_ignore_ascii_case(account) && m.flags.contains('c')) + }) } /// An account's effective channel capabilities, combining its direct access @@ -494,7 +500,7 @@ impl Db { let mut caps = Caps::default(); for a in &c.access { let applies = match a.account.strip_prefix('!') { - Some(g) => self.is_group_member(&format!("!{g}"), account), + Some(g) => self.group_grants_channel_access(&format!("!{g}"), account), None => a.account.eq_ignore_ascii_case(account), }; if applies { diff --git a/src/engine/db/tests.rs b/src/engine/db/tests.rs index 1c170e1..5d0e3e2 100644 --- a/src/engine/db/tests.rs +++ b/src/engine/db/tests.rs @@ -751,14 +751,14 @@ // Sanity: every reference is in place. assert_eq!(db.channel("#foo").unwrap().join_mode("alice"), Some("+o"), "alice starts as an op"); assert_eq!(db.channel_successor("#bar").as_deref(), Some("alice")); - assert!(db.is_group_member("!bobgrp", "alice")); + assert!(db.group("!bobgrp").unwrap().members.iter().any(|m| m.account.eq_ignore_ascii_case("alice"))); assert!(db.group("!alicegrp").is_some()); // Dropping alice erases all of them. assert!(db.drop_account("alice").unwrap()); assert_eq!(db.channel("#foo").unwrap().join_mode("alice"), None, "access grant purged"); assert_eq!(db.channel_successor("#bar"), None, "successorship purged"); - assert!(!db.is_group_member("!bobgrp", "alice"), "group membership purged"); + assert!(!db.group("!bobgrp").unwrap().members.iter().any(|m| m.account.eq_ignore_ascii_case("alice")), "group membership purged"); assert!(db.group("!alicegrp").is_none(), "founderless group dropped"); // Re-registering the name must not inherit the old op access. diff --git a/src/engine/tests.rs b/src/engine/tests.rs index 533a8c2..88e3235 100644 --- a/src/engine/tests.rs +++ b/src/engine/tests.rs @@ -4438,7 +4438,7 @@ } // GroupServ interconnection: a channel grants access to a !group, and every - // group member inherits that channel access (auto-op on join). + // group member holding the c (channel-access) flag inherits it (auto-op on join). #[test] fn groupserv_grants_channel_access() { use echo_chanserv::ChanServ; @@ -4474,8 +4474,11 @@ assert!(has(&gs(&mut e, "000AAAAAA", "ADD !team bob"), "Added"), "bob added"); assert!(has(&cs(&mut e, "000AAAAAA", "FLAGS #room !team +o"), "now holds"), "group granted channel op"); - // bob, a group member, is auto-opped on join; carol (not in the group) isn't. - assert!(opped(&e.handle(NetEvent::Join { uid: "000AAAAAB".into(), channel: "#room".into(), op: false }), "000AAAAAB"), "group member auto-opped"); + // A member without the c (channel-access) flag does NOT inherit; +c makes + // bob auto-opped on join. carol (not in the group) never is. + assert!(!opped(&e.handle(NetEvent::Join { uid: "000AAAAAB".into(), channel: "#room".into(), op: false }), "000AAAAAB"), "no c flag, no access"); + gs(&mut e, "000AAAAAA", "FLAGS !team bob +c"); + assert!(opped(&e.handle(NetEvent::Join { uid: "000AAAAAB".into(), channel: "#room".into(), op: false }), "000AAAAAB"), "c flag -> auto-opped"); assert!(!opped(&e.handle(NetEvent::Join { uid: "000AAAAAC".into(), channel: "#room".into(), op: false }), "000AAAAAC"), "non-member not opped"); // Removing bob from the group revokes his inherited channel access.