From 5627975f94aaea2d2933bbbc4020a73d052c3ad0 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 31 Jan 2014 21:30:08 +0000 Subject: [PATCH] luci2: implement LuCI2.session.updateACLs() and LuCI2.session.hasACL() --- luci2/htdocs/luci2/luci2.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/luci2/htdocs/luci2/luci2.js b/luci2/htdocs/luci2/luci2.js index c4dbbd6..58d38df 100644 --- a/luci2/htdocs/luci2/luci2.js +++ b/luci2/htdocs/luci2/luci2.js @@ -2205,6 +2205,41 @@ function LuCI2() window.clearInterval(this._hearbeatInterval); delete this._hearbeatInterval; } + }, + + + _acls: { }, + + _fetch_acls: _luci2.rpc.declare({ + object: 'session', + method: 'access', + expect: { '': { } } + }), + + _fetch_acls_cb: function(acls) + { + _luci2.session._acls = acls; + }, + + updateACLs: function() + { + return _luci2.session._fetch_acls() + .then(_luci2.session._fetch_acls_cb); + }, + + hasACL: function(scope, object, func) + { + var acls = _luci2.session._acls; + + if (typeof(func) == 'undefined') + return (acls && acls[scope] && acls[scope][object]); + + if (acls && acls[scope] && acls[scope][object]) + for (var i = 0; i < acls[scope][object].length; i++) + if (acls[scope][object][i] == func) + return true; + + return false; } }; -- 2.11.0