mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-26 17:29:53 +01:00
fix: #8003, check children recursively
This commit is contained in:
@@ -238,7 +238,7 @@ async function getCategoryData(cids, uid, selectedCid, states) {
|
|||||||
const cidToWatchState = _.zipObject(cids, watchState);
|
const cidToWatchState = _.zipObject(cids, watchState);
|
||||||
|
|
||||||
const visibleCategories = categoryData.filter(function (c) {
|
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 isCategoryVisible = c && cidToAllowed[c.cid] && !c.link && !c.disabled && states.includes(cidToWatchState[c.cid]);
|
||||||
const shouldBeRemoved = !hasVisibleChildren && !isCategoryVisible;
|
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) {
|
helpers.getHomePageRoutes = async function (uid) {
|
||||||
let cids = await categories.getAllCidsFromSet('categories:cid');
|
let cids = await categories.getAllCidsFromSet('categories:cid');
|
||||||
cids = await privileges.categories.filterCids('find', cids, uid);
|
cids = await privileges.categories.filterCids('find', cids, uid);
|
||||||
|
|||||||
Reference in New Issue
Block a user