From 25575d1111f2a68b14bf27ee4811b9db4e4caba4 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 27 Nov 2026 05:46:16 +0300 Subject: [PATCH] Identify newly created groups by type and pre-request IDs --- CHANGELOG.md | 2 ++ core/src/admin.rs | 41 +++++++++++++++++++++++++++++++----- core/src/admin_extra.rs | 2 +- core/src/admin_session.rs | 6 +++++- docs/bridge.md | 2 +- docs/mobile-port-progress.md | 2 ++ 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4dbe18..827ee85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Group creation no longer returns an existing group or a same-name group of another type as the newly created group. Follow-up permissions require one matching new ID. + - Searching a channel directory filters the loaded file names locally. Refreshing the same folder keeps the filter; opening another folder clears it. - Searching or paging the client database now refreshes permission hints just like opening the first page, without losing the query or page offset. diff --git a/core/src/admin.rs b/core/src/admin.rs index e46cc31..6f95c07 100644 --- a/core/src/admin.rs +++ b/core/src/admin.rs @@ -680,7 +680,7 @@ pub enum Reply { Created { name: String, parent: u64, invoker: u16, channel_id: Option, ambiguous: bool }, /// `tokenadd`: the key comes from `notifytokenadd`. Token { token: Option }, - GroupCreated { notify: &'static str, key: &'static str, name: String, group_id: Option, ambiguous: bool }, + GroupCreated { notify: &'static str, key: &'static str, name: String, group_type: u8, existing: std::collections::HashSet, group_id: Option, ambiguous: bool }, /// `channelgetdescription`: the description comes from `notifychanneledited`. Description { channel_id: u64, description: Option }, ChannelInfo { channel_id: u64 }, @@ -729,10 +729,10 @@ impl Reply { } } } - Reply::GroupCreated { notify, key, name, group_id, ambiguous } if *notify == raw.name => { + Reply::GroupCreated { notify, key, name, group_type, existing, group_id, ambiguous } if *notify == raw.name => { for row in &raw.items { - if row.get("name") == Some(name) { - if let Some(id) = row.get(*key).and_then(|v| v.parse::().ok()) { + if row.get("name") == Some(name) && row.get("type").and_then(|v| v.parse::().ok()) == Some(*group_type) { + if let Some(id) = row.get(*key).and_then(|v| v.parse::().ok()).filter(|id| *id != 0 && !existing.contains(id)) { if group_id.is_some_and(|old| old != id) { *ambiguous = true; } *group_id = Some(id); } @@ -792,6 +792,7 @@ pub struct Live<'a> { pub own_client: u16, pub server_uid: &'a str, pub channel: &'a dyn Fn(u64) -> Option, + pub group_ids: &'a dyn Fn(extra::GroupKind) -> std::collections::HashSet, } /// Checks the destructive-action confirmation against the live target. @@ -992,7 +993,37 @@ mod tests { fn content(cmd: OutCommand) -> String { String::from_utf8(cmd.into_packet().content().to_vec()).unwrap() } fn live<'a>(channel: &'a dyn Fn(u64) -> Option) -> Live<'a> { - Live { own_client: 7, server_uid: "srv=", channel } + Live { own_client: 7, server_uid: "srv=", channel, group_ids: &|_| Default::default() } + } + + #[test] + fn group_add_requires_a_unique_new_id_of_the_requested_type() { + use extra::GroupKind; + let group_ids = |kind| match kind { + GroupKind::Server => [4].into_iter().collect(), + GroupKind::Channel => [9].into_iter().collect(), + }; + let state = Live { group_ids: &group_ids, ..live(&|_| None) }; + for (kind, notify, key, old) in [("server", "notifyservergrouplist", "sgid", 4), ("channel", "notifychannelgrouplist", "cgid", 9)] { + let cmd = parse_json("group_add", json!({"generation":1,"kind":kind,"name":"Operators","type":1})).unwrap(); + let begin = || build(&cmd, &state).unwrap().1; + let collect = |r: &mut Reply, id: u64, ty: u8| { + let packet = format!("{notify} {key}={id} type={ty} name=Operators"); + r.collect(&crate::rawcmd::parse(packet.as_bytes()).unwrap()); + }; + let mut missing = begin(); + collect(&mut missing, old, 1); collect(&mut missing, 0, 1); collect(&mut missing, 31, 0); + let error = finish(missing).unwrap_err(); + assert_eq!(error.code, ErrorCode::ServerError); + assert_eq!(error.detail, Some(json!({"created":true}))); + let mut unique = begin(); + collect(&mut unique, old, 1); collect(&mut unique, 31, 0); + collect(&mut unique, 32, 1); collect(&mut unique, 32, 1); + assert_eq!(finish(unique).unwrap(), json!({"group_id":32})); + let mut ambiguous = begin(); + collect(&mut ambiguous, 32, 1); collect(&mut ambiguous, 33, 1); + assert_eq!(finish(ambiguous).unwrap_err().detail, Some(json!({"created":true}))); + } } #[test] diff --git a/core/src/admin_extra.rs b/core/src/admin_extra.rs index 1cf4664..87c3b43 100644 --- a/core/src/admin_extra.rs +++ b/core/src/admin_extra.rs @@ -91,7 +91,7 @@ impl Command { Self::ChannelGroupList{}=>(menu::command("channelgrouplist",&[]),Reply::rows("notifychannelgrouplist",None)), Self::GroupAdd{kind,name,group_type,..}=>{ let (verb,notify,key)=group_names(*kind,"add"); - (menu::command(verb,&[("name",name.clone()),("type",group_type.to_string())]),Reply::GroupCreated{notify,key,name:name.clone(),group_id:None,ambiguous:false}) + (menu::command(verb,&[("name",name.clone()),("type",group_type.to_string())]),Reply::GroupCreated{notify,key,name:name.clone(),group_type:*group_type,existing:(live.group_ids)(*kind),group_id:None,ambiguous:false}) }, Self::GroupRename{kind,group_id,name,..}=>{let(verb,_,key)=group_names(*kind,"rename");(menu::command(verb,&[(key,s(*group_id)),("name",name.clone())]),Reply::Ack)}, Self::GroupSetPermissions{kind,group_id,permissions,..}=>{let(verb,_,key)=group_names(*kind,"perm");(permission_command(verb,key,*group_id,permissions,*kind==GroupKind::Server),Reply::Ack)}, diff --git a/core/src/admin_session.rs b/core/src/admin_session.rs index a8b2587..9fbc364 100644 --- a/core/src/admin_session.rs +++ b/core/src/admin_session.rs @@ -155,7 +155,11 @@ impl Session { other => { let server_uid = book.server.public_key.get_uid(); let channel = |cid: u64| book.channels.get(&ChannelId(cid)).map(|ch| ch.name.clone()); - let live = admin::Live { own_client: book.own_client.0, server_uid: &server_uid, channel: &channel }; + let group_ids = |kind| match kind { + admin::extra::GroupKind::Server => book.server_groups.keys().map(|id| id.0).collect(), + admin::extra::GroupKind::Channel => book.channel_groups.keys().map(|id| id.0).collect(), + }; + let live = admin::Live { own_client: book.own_client.0, server_uid: &server_uid, channel: &channel, group_ids: &group_ids }; admin::build(other, &live)? } }; diff --git a/docs/bridge.md b/docs/bridge.md index c7a200f..5d421f0 100644 --- a/docs/bridge.md +++ b/docs/bridge.md @@ -698,7 +698,7 @@ For an isolated Windows beta14 fixture at `127.0.0.1:19987`, set `TEAMSPEACH_QA_ | `server_group_perm_list` / `channel_group_perm_list` | `{group_id}` | | `channel_perm_list` | `{channel_id}` | | `server_group_client_list` | `{group_id}`; sends `-names` to include UID/nickname | -| `group_add` | `{generation,kind:"server"|"channel",name,type:0|1|2}` → `{group_id}`; missing/ambiguous resulting ID fails with created detail | +| `group_add` | `{generation,kind:"server"|"channel",name,type:0|1|2}` → `{group_id}`. The group list must identify one positive ID not present in the live book for this kind before dispatch, matching the requested name and type. Repeated rows for the same ID are allowed. If creation was accepted but no unique ID was identified, the error detail contains `created: true`; reload the list instead of retrying creation. | | `group_rename` | `{generation,kind,group_id,name}` | | `group_set_permissions` | `{generation,kind,group_id,permissions:[{id:string,value:i32,negate?,skip?}]}`; 1..512 rows; negate/skip only server group | | `channel_set_permissions` | `{generation,channel_id,permissions:[{id:string,value:i32}]}` | diff --git a/docs/mobile-port-progress.md b/docs/mobile-port-progress.md index 2894cf7..203890c 100644 --- a/docs/mobile-port-progress.md +++ b/docs/mobile-port-progress.md @@ -4,6 +4,8 @@ ## Возврат к разработке на ПК, 2026-11-26 +Windows, база `d841530`: для `group_add` ядро исключает ранее известные ID групп нужной категории и сверяет имя и тип ответа. Проверены нулевой ID, повтор одного нового ID и неоднозначный ответ. Прошли три теста ядра и два теста импорта снимков. Создание серверной или канальной группы на живом стенде этим прогоном не подтверждено. + Windows, база `643d0e4`: поиск в браузере файлов фильтрует загруженные имена, сохраняет переход к родителю и сбрасывается при смене каталога. Тест Slint проверил обновление списка, регистр кириллицы и цель контекстного меню. Прошли три адресных теста; сетевой обмен файлами не проверялся. Windows, база `3a8e15e`: поиск и перелистывание базы клиентов используют тот же контекст прав, что и первая страница. Три адресных теста прошли, включая сохранение смещения, строки поиска, ID записи и сессии. Живой запрос базы и удаление записи не проверялись.