luci-base: dispatcher.uc: apply ACLs to menu tree JSON
authorJo-Philipp Wich <jo@mein.io>
Wed, 2 Nov 2022 09:09:05 +0000 (10:09 +0100)
committerJo-Philipp Wich <jo@mein.io>
Wed, 2 Nov 2022 09:13:41 +0000 (10:13 +0100)
Add menu tree annotations for node readonly and dependency satisfied state
in order to ensure that unreachable menu nodes are hidden from view.

Fixes: ded8ccf93e ("luci-base-ucode: add initial ucode based LuCI runtime")
Ref: https://forum.openwrt.org/t/x/141426/10
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/ucode/dispatcher.uc

index 805abc4ce0130a97cb7a4ab617ecbf62ea2f411a..86cab9b88f6204997059e63485180cecdc4bf5ed 100644 (file)
@@ -423,9 +423,24 @@ function build_pagetree() {
        return tree;
 }
 
+function apply_tree_acls(node, acl) {
+       for (let name, spec in node?.children)
+               apply_tree_acls(spec, acl);
+
+       if (node?.depends?.acl) {
+               switch (check_acl_depends(node.depends.acl, acl["access-group"])) {
+               case null:  node.satisfied = false; break;
+               case false: node.readonly = true;   break;
+               }
+       }
+}
+
 function menu_json(acl) {
        tree ??= build_pagetree();
 
+       if (acl)
+               apply_tree_acls(tree, acl);
+
        return tree;
 }