luci2: implement LuCI2.session.updateACLs() and LuCI2.session.hasACL()
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 31 Jan 2014 21:30:08 +0000 (21:30 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Fri, 31 Jan 2014 21:30:08 +0000 (21:30 +0000)
luci2/htdocs/luci2/luci2.js

index c4dbbd6ae9db5d7828a48e45730600c03c5ac7a5..58d38df249aad5efcb159b8249d36739ae45079f 100644 (file)
@@ -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;
                }
        };