'use strict';
'require ui';
'require uci';
+'require rpc';
'require dom';
'require baseclass';
var scope = this;
+var callSessionAccess = rpc.declare({
+ object: 'session',
+ method: 'access',
+ params: [ 'scope', 'object', 'function' ],
+ expect: { 'access': false }
+});
+
var CBIJSONConfig = baseclass.extend({
__init__: function(data) {
data = Object.assign({}, data);
this.config = config;
this.parsechain = [ config ];
- this.readonly = false;
this.data = uci;
},
* If set to `true`, the Map instance is marked readonly and any form
* option elements added to it will inherit the readonly state.
*
+ * If left unset, the Map will test the access permission of the primary
+ * uci configuration upon loading and mark the form readonly if no write
+ * permissions are granted.
+ *
* @name LuCI.form.Map.prototype#readonly
* @type boolean
*/
* an error.
*/
load: function() {
- return this.data.load(this.parsechain || [ this.config ])
- .then(this.loadChildren.bind(this));
+ var doCheckACL = (!(this instanceof CBIJSONMap) && this.readonly == null);
+
+ return Promise.all([
+ doCheckACL ? callSessionAccess('uci', this.config, 'write') : true,
+ this.data.load(this.parsechain || [ this.config ])
+ ]).then(L.bind(function(res) {
+ if (res[0] === false)
+ this.readonly = true;
+
+ return this.loadChildren();
+ }, this));
},
/**