Recheck channel move topology before dispatch
This commit is contained in:
1 parent
9b19e96271
commit
8930007945
5 files changed
+60
-2
No files matched your search
@@ -3,6 +3,7 @@
|
||||
## Unreleased
|
||||
|
||||
- Move Channel opens at the channel's current position. Selecting a new parent offers First and that parent's children; the moving channel and its descendants are excluded from the destinations.
|
||||
The core also checks the destination against the current tree when the move is submitted, so a predecessor that has since moved or disappeared cannot silently redirect the operation.
|
||||
|
||||
- Channel information and lists now show the current parent and preceding sibling after a neighboring channel moves.
|
||||
|
||||
|
||||
+3
-1
@@ -618,8 +618,9 @@ pub(crate) fn validate(command: &AdminCommand) -> Result<(), ErrorObj> {
|
||||
positive("channel_id", *channel_id)?;
|
||||
}
|
||||
C::ServerEdit { properties, .. } => properties.check_scope(PropertyScope::ServerEdit)?,
|
||||
C::ChannelMove { channel_id, parent_id, .. } => {
|
||||
C::ChannelMove { channel_id, parent_id, order, .. } => {
|
||||
if parent_id == channel_id { return Err(bad("a channel cannot be its own parent")); }
|
||||
if order.as_ref() == Some(channel_id) { return Err(bad("a channel cannot precede itself")); }
|
||||
positive("channel_id", *channel_id)?;
|
||||
}
|
||||
C::ChannelDelete { channel_id, .. } | C::ChannelSubscribe { channel_id, .. }
|
||||
@@ -965,6 +966,7 @@ mod tests {
|
||||
fn direct_admin_and_permission_arguments_reject_invalid_values() {
|
||||
use extra::{Command as E, GroupKind, Permission};
|
||||
let invalid = [
|
||||
AdminCommand::ChannelMove { generation: 1, channel_id: 9, parent_id: 0, order: Some(9) },
|
||||
AdminCommand::BanDelete { generation: 0, ban_id: 1, confirm: "1".into() },
|
||||
AdminCommand::SetAway { away: false, message: Some("reason".into()) },
|
||||
AdminCommand::TalkRequest { request: true, message: Some("x".repeat(51)) },
|
||||
|
||||
@@ -1,6 +1,54 @@
|
||||
//! Session integration of server/channel administration (`admin.rs`, `docs/bridge.md` §4.6).
|
||||
use super::*;
|
||||
|
||||
fn validate_move_position(
|
||||
moving: u64, parent: u64, order: Option<u64>, channel_count: usize,
|
||||
parent_of: impl Fn(u64) -> Option<u64>,
|
||||
) -> Result<(), ErrorObj> {
|
||||
if let Some(after) = order.filter(|id| *id != 0) {
|
||||
if after == moving || parent_of(after) != Some(parent) {
|
||||
return Err(ErrorObj::new(ErrorCode::TargetChanged, "preceding channel is no longer a sibling; reopen the move dialog"));
|
||||
}
|
||||
}
|
||||
let mut ancestor = parent;
|
||||
// Even an inconsistent book with a parent cycle must finish without a network write.
|
||||
for _ in 0..channel_count {
|
||||
if ancestor == 0 { return Ok(()); }
|
||||
if ancestor == moving { break; }
|
||||
let Some(next) = parent_of(ancestor) else { break };
|
||||
ancestor = next;
|
||||
}
|
||||
if ancestor == 0 { Ok(()) } else {
|
||||
Err(ErrorObj::new(ErrorCode::TargetChanged, "destination is no longer a valid parent; reopen the move dialog"))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod move_tests {
|
||||
use super::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[test]
|
||||
fn channel_move_rechecks_parent_and_predecessor_at_dispatch() {
|
||||
let mut parents = HashMap::from([(42, 0), (8, 0), (13, 8), (99, 42)]);
|
||||
let check = |parents: &HashMap<u64,u64>, parent, order| {
|
||||
validate_move_position(42, parent, order, parents.len(), |id| parents.get(&id).copied())
|
||||
};
|
||||
check(&parents, 8, Some(13)).unwrap();
|
||||
check(&parents, 8, Some(0)).unwrap();
|
||||
check(&parents, 0, None).unwrap();
|
||||
parents.insert(13, 0);
|
||||
assert_eq!(check(&parents, 8, Some(13)).unwrap_err().code, ErrorCode::TargetChanged);
|
||||
check(&parents, 0, Some(13)).unwrap();
|
||||
parents.remove(&13);
|
||||
assert_eq!(check(&parents, 0, Some(13)).unwrap_err().code, ErrorCode::TargetChanged);
|
||||
parents.insert(8, 99);
|
||||
assert_eq!(check(&parents, 8, Some(0)).unwrap_err().code, ErrorCode::TargetChanged);
|
||||
parents.insert(99, 8);
|
||||
assert_eq!(check(&parents, 8, None).unwrap_err().code, ErrorCode::TargetChanged);
|
||||
}
|
||||
}
|
||||
|
||||
impl Session {
|
||||
pub(super) async fn admin(&mut self, id: &str, cmd: admin::AdminCommand) -> Result<Option<Value>, ErrorObj> {
|
||||
let c = self.connected_conn()?;
|
||||
@@ -11,6 +59,11 @@ impl Session {
|
||||
}
|
||||
}
|
||||
let book = c.con.get_state().map_err(|e| lib_error(ErrorCode::NotConnected, &e))?;
|
||||
if let admin::AdminCommand::ChannelMove { channel_id, parent_id, order, .. } = &cmd {
|
||||
validate_move_position(*channel_id, *parent_id, *order, book.channels.len(), |id| {
|
||||
book.channels.get(&ChannelId(id)).map(|channel| channel.parent.0)
|
||||
})?;
|
||||
}
|
||||
let (command, reply) = match &cmd {
|
||||
admin::AdminCommand::Context => (menu::command("permissionlist", &[]), admin::Reply::Context),
|
||||
admin::AdminCommand::Extra(admin::extra::Command::ChannelList {}) => {
|
||||
|
||||
+1
-1
@@ -667,7 +667,7 @@ For an isolated Windows beta14 fixture at `127.0.0.1:19987`, set `TEAMSPEACH_QA_
|
||||
|---|---|
|
||||
| `channel_create` | `{generation,parent_id,properties}` → `{channel_id}` from own channel-created event |
|
||||
| `channel_edit` | `{generation,channel_id,properties}` |
|
||||
| `channel_move` | `{generation,channel_id,parent_id,order?}` |
|
||||
| `channel_move` | `{generation,channel_id,parent_id,order?}`; parent 0 means server root, order 0 means first. A nonzero predecessor must still belong to the destination parent. A missing or cyclic destination ancestry, a destination below the moving channel, or a stale predecessor is refused before sending. |
|
||||
| `channel_delete` | `{generation,channel_id,force,confirm}`; confirm exact current channel name |
|
||||
| `channel_subscribe` / `channel_subscribe_all` | `{channel_id,subscribe}` / `{subscribe}` |
|
||||
| `channel_description` | `{channel_id}` → `{description}` |
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
## Возврат к разработке на ПК, 2026-11-26
|
||||
|
||||
Windows, база `9b19e96`: ядро перед отправкой `channel_move` проверяет, что предшественник всё ещё принадлежит выбранному родителю и новая ветка не замыкает цикл. Три адресных теста прошли, включая исчезновение или перемещение предшественника, перенос родителя в исходное поддерево и допустимую первую позицию. Серверное подтверждение переноса в этот прогон не входило.
|
||||
|
||||
Windows, база `cc3cb27`: диалог переноса канала показывает текущего родителя и предшественника. При смене родителя предлагает первую позицию и только соседние каналы. Тест Slint выбрал второй из двух одноимённых каналов и получил `channel_id=42, parent_id=8, order=13`. Шесть адресных тестов прошли. Это проверка формы и аргументов команды, не подтверждение перемещения на сервере.
|
||||
|
||||
Windows, база `be1d308`: сценарий `channel_admin_qa --channel-order` собран и запущен с актуальным диагностическим ядром. Гость beta14 получил TS 2568 на `channel_create` с явной позицией. Проверка порядка завершилась кодом 1; отключение подтверждено сервером, временный профиль удалён, стенд остановлен с кодом 0. Живой результат изменения порядка не установлен.
|
||||
|
||||
Reference in new issue
Block a user