From 50f24a174ffe1ba4d2e8061020c56c74fb2ae2d0 Mon Sep 17 00:00:00 2001 From: khorshuheng Date: Thu, 5 Sep 2024 14:35:55 +0800 Subject: [PATCH] fix: filter out children which the view's parent does not match the actual parent view id --- src/biz/collab/publish_outline.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/biz/collab/publish_outline.rs b/src/biz/collab/publish_outline.rs index 6dd047ca9..eb9ba5bf3 100644 --- a/src/biz/collab/publish_outline.rs +++ b/src/biz/collab/publish_outline.rs @@ -53,13 +53,24 @@ pub fn collab_folder_to_published_outline( .children .iter() .filter(|v| !unviewable.contains(&v.id)) - .filter_map(|v| to_publish_view(&v.id, folder, &unviewable, publish_view_ids, 0, max_depth)) + .filter_map(|v| { + to_publish_view( + &root.id, + &v.id, + folder, + &unviewable, + publish_view_ids, + 0, + max_depth, + ) + }) .collect(), }; Ok(published_view) } fn to_publish_view( + parent_view_id: &str, view_id: &str, folder: &Folder, unviewable: &HashSet, @@ -77,6 +88,12 @@ fn to_publish_view( return None; }, }; + + // There is currently a bug, in which the parent_view_id is not always set correctly + if view.parent_view_id != parent_view_id { + return None; + } + let extra = view.extra.as_deref().map(|extra| { serde_json::from_str::(extra).unwrap_or_else(|e| { tracing::warn!("failed to parse extra field({}): {}", extra, e); @@ -87,9 +104,10 @@ fn to_publish_view( .children .iter() .filter(|v| !unviewable.contains(&v.id)) - .filter_map(|view_id| { + .filter_map(|child_view_id| { to_publish_view( - &view_id.id, + view_id, + &child_view_id.id, folder, unviewable, publish_view_ids,