Resolve omitted group types from the matching session roster

This commit is contained in:
omar committed 2026-11-28 05:40:32 +03:00
1 parent 62ab1896e5
commit 6368b84915
5 files changed
+45 -3

No files matched your search

+34 -3
View File
@@ -171,12 +171,34 @@ pub(crate) fn permissions_detail(t: &Target, snapshot: &Value, context: &Value,
}
let can_rename = allows(rename);
let can_delete = allows(delete);
let mut roster_by_id = None;
for row in rows {
let id = if wire { row.get(key).and_then(wire_uint) } else { row.get("id").and_then(Value::as_u64) };
let id = id.filter(|id| (1..=MAX_SAFE_INTEGER).contains(id)).ok_or_else(|| invalid("Invalid source group ID"))?;
let name = row.get("name").and_then(Value::as_str).ok_or_else(|| invalid("Missing group name"))?;
let group_type = row.get("type");
let regular = if wire {
match group_type.and_then(wire_uint) {
Some(1) => true,
Some(0 | 2) => false,
None if group_type.is_none_or(|v| v.is_null() || v.as_str() == Some("")) => {
// beta14 can omit type. Use only the matching group from this catalog and session.
if roster_by_id.is_none() {
let roster = snapshot[list].as_array().filter(|r| r.len() <= MAX_ROWS)
.ok_or_else(|| invalid("Missing typed group catalog"))?;
let mut index = std::collections::HashMap::with_capacity(roster.len());
for group in roster {
let id = group["id"].as_u64().ok_or_else(|| invalid("Invalid snapshot group ID"))?;
if index.insert(id, group).is_some() { return Err(invalid("Duplicate snapshot group ID")); }
}
roster_by_id = Some(index);
}
match roster_by_id.as_ref().and_then(|index|index.get(&id)).filter(|g|g["name"]==name).and_then(|g|g["type"].as_str()) {
Some("regular") => true,
Some("template" | "query") => false,
_ => return Err(invalid("Missing matching typed group")),
}
}
_ => return Err(invalid("Invalid wire group type")),
}
} else {
@@ -186,9 +208,6 @@ pub(crate) fn permissions_detail(t: &Target, snapshot: &Value, context: &Value,
_ => return Err(invalid("Invalid snapshot group type")),
}
};
let id = if wire { row.get(key).and_then(wire_uint) } else { row.get("id").and_then(Value::as_u64) };
let id = id.filter(|id| (1..=MAX_SAFE_INTEGER).contains(id)).ok_or_else(|| invalid("Invalid source group ID"))?;
let name = row.get("name").and_then(Value::as_str).ok_or_else(|| invalid("Missing group name"))?;
if !regular {
continue;
}
@@ -339,6 +358,18 @@ mod tests {
assert!(detail.entries.iter().all(|entry| entry.target.session == target.session));
}
#[test]
fn sparse_refresh_requires_same_catalog_id_and_name() {
let project = |kind, reply: Value| permissions_detail(&permissions_target(), &permissions_snapshot(), &permissions_context(), Some((kind, &reply)), &Catalog::default());
let detail = project(GroupKind::Server, json!({"rows":[{"sgid":"8","name":"Server template","type":""},{"sgid":"7","name":"Server group"}]})).unwrap();
assert_eq!(groups(&detail), [("sgid:7", "Server group"), ("cgid:7", "Channel group")]);
let detail = project(GroupKind::Channel, json!({"rows":[{"cgid":8,"name":"Channel query","type":null}]})).unwrap();
assert_eq!(groups(&detail), [("sgid:7", "Server group")]);
for row in [json!({"sgid":7,"name":"Channel group"}), json!({"sgid":9,"name":"Server group"}), json!({"sgid":7,"name":"Server group","type":"bad"})] {
assert!(matches!(project(GroupKind::Server, json!({"rows":[row]})), Err(e) if e.code=="bad_response"));
}
}
#[test]
fn permissions_detail_replaces_only_the_refreshed_kind_and_filters_wire_types() {
let target = permissions_target();
+5
View File
@@ -105,6 +105,11 @@ pub(super) async fn exercise(runtime: &AppRuntime, ui: &AppWindow, owner: &Runti
(&channels, "channel_groups", "cgid", "channel", "b_virtualserver_channelgroup_rename", "b_virtualserver_channelgroup_delete"),
] {
let expected = regular_groups(reply, &server[snapshot_key], id_field)?;
let source = if id_field == "sgid" { teamspeach_core::admin::extra::GroupKind::Server } else { teamspeach_core::admin::extra::GroupKind::Channel };
let refreshed = crate::app::server_actions::permissions_detail(target, server, &context, Some((source, reply)), &catalog)
.map_err(|e|format!("{kind} group refresh: {}", e.message))?;
let refreshed_rows = refreshed.entries.iter().filter_map(|e|e.id.strip_prefix(id_field)?.strip_prefix(':')?.parse::<u64>().ok().map(|id|(id,e.title.as_str()))).collect::<BTreeMap<_,_>>();
if refreshed_rows != expected {return Err(format!("refreshed {kind} catalog differs from acknowledged groups"));}
count += expected.len();
for (id, name) in expected {
let entity = if id_field == "sgid" { Entity::ServerGroup { id } } else { Entity::ChannelGroup { id } };