From: Jo-Philipp Wich Date: Fri, 31 Jan 2014 21:30:08 +0000 (+0000) Subject: luci2: implement LuCI2.session.updateACLs() and LuCI2.session.hasACL() X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=5627975f94aaea2d2933bbbc4020a73d052c3ad0;p=project%2Fluci2%2Fui.git luci2: implement LuCI2.session.updateACLs() and LuCI2.session.hasACL() --- 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; } };