Node.js based forum software built for the modern web
fix: #8003, check children recursively
Barış Soner Uşaklıc4e58160cf32
diff --git a/src/controllers/helpers.js b/src/controllers/helpers.jsindex 9a5877e0b4..4240ecb637 100644--- a/src/controllers/helpers.js+++ b/src/controllers/helpers.js@@ -238,7 +238,7 @@ async function getCategoryData(cids, uid, selectedCid, states) {const cidToWatchState = _.zipObject(cids, watchState);const visibleCategories = categoryData.filter(function (c) {- const hasVisibleChildren = c && Array.isArray(c.children) && c.children.some(c => c && cidToAllowed[c.cid] && states.includes(cidToWatchState[c.cid]));+ const hasVisibleChildren = checkVisibleChildren(c, cidToAllowed, cidToWatchState, states);const isCategoryVisible = c && cidToAllowed[c.cid] && !c.link && !c.disabled && states.includes(cidToWatchState[c.cid]);const shouldBeRemoved = !hasVisibleChildren && !isCategoryVisible;@@ -281,6 +281,15 @@ async function getCategoryData(cids, uid, selectedCid, states) {};}+function checkVisibleChildren(c, cidToAllowed, cidToWatchState, states) {+ if (!c || !Array.isArray(c.children)) {+ return false;+ }+ return c.children.some(c => c && (+ (cidToAllowed[c.cid] && states.includes(cidToWatchState[c.cid])) || checkVisibleChildren(c, cidToAllowed, cidToWatchState, states)+ ));+}+helpers.getHomePageRoutes = async function (uid) {let cids = await categories.getAllCidsFromSet('categories:cid');cids = await privileges.categories.filterCids('find', cids, uid);