-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadd_role_to_read_permission.js
More file actions
30 lines (25 loc) · 1.03 KB
/
add_role_to_read_permission.js
File metadata and controls
30 lines (25 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
* This script adds a role to the read permissions for a set of data points.
* By default it adds the user role to all points on the internal data source.
*/
// imports
const pointService = services.dataPointService;
const roleService = services.roleService;
const HashSet = Java.type('java.util.HashSet');
const MangoPermission = Java.type('com.infiniteautomation.mango.permission.MangoPermission');
// Set the XID of role to add here
const role = roleService.get('user').getRole();
let index = 0;
pointService.buildQuery()
// set the data source XID here
.equal('dataSourceXid', 'internal_mango_monitoring_ds')
.query(point => {
const minTerms = new HashSet(point.getReadPermission().getRoles());
const term = new HashSet();
term.add(role);
minTerms.add(term);
const newPermission = new MangoPermission(minTerms);
point.setReadPermission(newPermission);
pointService.update(point.getXid(), point);
log.info('Saved point {} with XID {}', index++, point.getXid());
});