Adding client side check of setVariable with writableBy property

This commit is contained in:
David Négrier 2021-07-06 10:58:12 +02:00
parent 86fa869b20
commit cb78ff333b
5 changed files with 95 additions and 11 deletions

View file

@ -7,9 +7,14 @@ WA.onInit().then(() => {
console.log('Successfully caught error: ', e);
});
console.log('Trying to set variable "config". This should work.');
WA.room.saveVariable('config', {'foo': 'bar'});
console.log('Trying to set variable "myvar". This should work.');
WA.room.saveVariable('myvar', {'foo': 'bar'});
console.log('Trying to read variable "config". This should display a {"foo": "bar"} object.');
console.log(WA.room.loadVariable('config'));
console.log('Trying to read variable "myvar". This should display a {"foo": "bar"} object.');
console.log(WA.room.loadVariable('myvar'));
console.log('Trying to set variable "config". This should not work because we are not logged as admin.');
WA.room.saveVariable('config', {'foo': 'bar'}).catch(e => {
console.log('Successfully caught error because variable "config" is not writable: ', e);
});
});

View file

@ -104,6 +104,44 @@
"width":0,
"x":131.38069962269,
"y":106.004988169086
},
{
"height":0,
"id":9,
"name":"myvar",
"point":true,
"properties":[
{
"name":"default",
"type":"string",
"value":"{}"
},
{
"name":"jsonSchema",
"type":"string",
"value":"{}"
},
{
"name":"persist",
"type":"bool",
"value":true
},
{
"name":"readableBy",
"type":"string",
"value":""
},
{
"name":"writableBy",
"type":"string",
"value":""
}],
"rotation":0,
"type":"variable",
"visible":true,
"width":0,
"x":88.8149900876127,
"y":147.75212636695
}],
"opacity":1,
"type":"objectgroup",
@ -112,7 +150,7 @@
"y":0
}],
"nextlayerid":8,
"nextobjectid":9,
"nextobjectid":10,
"orientation":"orthogonal",
"properties":[
{