From: Jo-Philipp Wich Date: Wed, 15 Apr 2020 20:14:44 +0000 (+0200) Subject: luci-base: luci.js: add hasViewPermission() helper X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b739fc17eabe9905889017127ac1de8f4e194819;p=oweals%2Fluci.git luci-base: luci.js: add hasViewPermission() helper Signed-off-by: Jo-Philipp Wich --- diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index 6d31332a8..519bf8fd6 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -3120,6 +3120,22 @@ }); }, + /** + * 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()}. *