luci-base: luci.js: add hasViewPermission() helper
authorJo-Philipp Wich <jo@mein.io>
Wed, 15 Apr 2020 20:14:44 +0000 (22:14 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 16 Apr 2020 11:30:35 +0000 (13:30 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/luci.js

index 6d31332a8193e197d819c041c74eac5613fe838d..519bf8fd6700b30dc37d2918a45fafefec55bce4 100644 (file)
                                        });
                },
 
+               /**
+                * Check whether a view has sufficient permissions.
+                *
+                * @return {boolean|null}
+                * Returns `null` if the current session has no permission at all to
+                * load resources required by the view. Returns `false` if readonly
+                * permissions are granted or `true` if at least one required ACL
+                * group is granted with write permissions.
+                */
+               hasViewPermission: function() {
+                       if (!this.isObject(env.nodespec) || !env.nodespec.satisfied)
+                           return null;
+
+                       return !env.nodespec.readonly;
+               },
+
                /**
                 * Deprecated wrapper around {@link LuCI.poll.remove Poll.remove()}.
                 *