use of com.infiniteautomation.mango.permission.MangoPermission in project ma-modules-public by infiniteautomation.
the class Upgrade3 method upgrade.
@Override
protected void upgrade() throws Exception {
OutputStream out = createUpdateLogOutputStream();
// Create permission columns
Map<String, String[]> scripts = new HashMap<>();
scripts.put(DatabaseType.MYSQL.name(), addPermissionsSQL);
scripts.put(DatabaseType.H2.name(), addPermissionsSQL);
scripts.put(DatabaseType.MSSQL.name(), addPermissionsSQL);
scripts.put(DatabaseType.POSTGRES.name(), addPermissionsSQL);
runScript(scripts, out);
// Convert permissions into roles
// Move current permissions to roles
ejt.query("SELECT id, togglePermission FROM maintenanceEvents", rs -> {
int voId = rs.getInt(1);
// Add role/mapping
MangoPermission togglePermissions = PermissionMigration.parseLegacyPermission(rs.getString(2));
Integer toggle = getOrCreatePermission(togglePermissions).getId();
ejt.update("UPDATE maintenanceEvents SET togglePermissionId=? WHERE id=?", toggle, voId);
});
// Modify permission columns
scripts = new HashMap<>();
scripts.put(DatabaseType.MYSQL.name(), permissionsNotNullMySQL);
scripts.put(DatabaseType.H2.name(), permissionsNotNullSQL);
scripts.put(DatabaseType.MSSQL.name(), permissionsNotNullSQL);
scripts.put(DatabaseType.POSTGRES.name(), permissionsNotNullSQL);
runScript(scripts, out);
scripts = new HashMap<>();
// Drop the togglePermissions
scripts.put(DatabaseType.MYSQL.name(), dropTogglePermission);
scripts.put(DatabaseType.H2.name(), dropTogglePermission);
scripts.put(DatabaseType.MSSQL.name(), dropTogglePermission);
scripts.put(DatabaseType.POSTGRES.name(), dropTogglePermission);
runScript(scripts, out);
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-modules-public by infiniteautomation.
the class MaintenanceEventDao method savePreRelationalData.
@Override
public void savePreRelationalData(MaintenanceEventVO existing, MaintenanceEventVO vo) {
MangoPermission togglePermission = permissionService.findOrCreate(vo.getTogglePermission());
vo.setTogglePermission(togglePermission);
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-modules-public by infiniteautomation.
the class MaintenanceEventDao method mapRecord.
@Override
public MaintenanceEventVO mapRecord(Record record) {
MaintenanceEventVO me = new MaintenanceEventVO();
me.setId(record.get(table.id));
me.setXid(record.get(table.xid));
me.setName(record.get(table.alias));
me.setAlarmLevel(AlarmLevels.fromValue(record.get(table.alarmLevel)));
me.setScheduleType(record.get(table.scheduleType));
me.setDisabled(charToBool(record.get(table.disabled)));
me.setActiveYear(record.get(table.activeYear));
me.setActiveMonth(record.get(table.activeMonth));
me.setActiveDay(record.get(table.activeDay));
me.setActiveHour(record.get(table.activeHour));
me.setActiveMinute(record.get(table.activeMinute));
me.setActiveSecond(record.get(table.activeSecond));
me.setActiveCron(record.get(table.activeCron));
me.setInactiveYear(record.get(table.inactiveYear));
me.setInactiveMonth(record.get(table.inactiveMonth));
me.setInactiveDay(record.get(table.inactiveDay));
me.setInactiveHour(record.get(table.inactiveHour));
me.setInactiveMinute(record.get(table.inactiveMinute));
me.setInactiveSecond(record.get(table.inactiveSecond));
me.setInactiveCron(record.get(table.inactiveCron));
me.setTimeoutPeriods(record.get(table.timeoutPeriods));
me.setTimeoutPeriodType(record.get(table.timeoutPeriodType));
me.setTogglePermission(new MangoPermission(record.get(table.togglePermissionId)));
return me;
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-modules-public by infiniteautomation.
the class Upgrade4 method upgrade.
@Override
protected void upgrade() throws Exception {
try (OutputStream out = createUpdateLogOutputStream()) {
// Get a reference to the superadmin permission in DB
MangoPermission superadmin = getOrCreatePermissionNoCache(MangoPermission.superadminOnly());
ejt.query("SELECT id, typeName, typeRef1 FROM events WHERE typeName=?", new Object[] { MaintenanceEventType.TYPE_NAME }, rs -> {
int eventId = rs.getInt(1);
Integer voId = rs.getInt(3);
// Find the permission id for this me
Integer permissionId = maintenanceEventPermissionMap.computeIfAbsent(voId, (k) -> {
// Build the permission for this event
Set<Role> allRequired = new HashSet<>();
List<Integer> dataPointIds = ejt.queryForList(SELECT_POINT_IDS, new Object[] { k }, Integer.class);
for (Integer dpId : dataPointIds) {
MangoPermission dataPointPermission = dataPointPermissionMap.computeIfAbsent(dpId, (pointId) -> {
Integer id = ejt.queryForInt("SELECT readPermissionId from dataPoints where id=?", new Object[] { pointId }, Common.NEW_ID);
if (id == Common.NEW_ID) {
return superadmin;
} else {
return permissionMap.computeIfAbsent(id, (pId) -> {
MangoPermission p = get(pId);
if (p == null) {
return superadmin;
} else {
return p;
}
});
}
});
dataPointPermission.getRoles().stream().forEach(minterm -> allRequired.addAll(minterm));
}
List<Integer> dataSourceIds = ejt.queryForList(SELECT_DATA_SOURCE_IDS, new Object[] { k }, Integer.class);
for (Integer dsId : dataSourceIds) {
MangoPermission dataSourcePermission = dataSourcePermissionMap.computeIfAbsent(dsId, (sourceId) -> {
Integer id = ejt.queryForInt("SELECT readPermissionId from dataSources where id=?", new Object[] { sourceId }, Common.NEW_ID);
if (id == Common.NEW_ID) {
return superadmin;
} else {
return permissionMap.computeIfAbsent(id, (pId) -> {
MangoPermission p = get(pId);
if (p == null) {
return superadmin;
} else {
return p;
}
});
}
});
dataSourcePermission.getRoles().stream().forEach(minterm -> allRequired.addAll(minterm));
}
MangoPermission permission;
if (allRequired.size() == 0) {
permission = MangoPermission.superadminOnly();
} else {
permission = MangoPermission.requireAllRoles(allRequired);
}
return getOrCreatePermission(permission).getId();
});
ejt.update("UPDATE events SET readPermissionId=? WHERE id=?", permissionId, eventId);
});
}
}
use of com.infiniteautomation.mango.permission.MangoPermission in project ma-modules-public by infiniteautomation.
the class SystemMetricsRestController method query.
@ApiOperation(value = "Get the current value for all System Metrics", notes = "TBD Add RQL Support to this endpoint")
@RequestMapping(method = RequestMethod.GET)
public List<ValueMonitorModel> query(@AuthenticationPrincipal User user) {
MangoPermission permission = definition.getPermission();
service.ensurePermission(user, permission);
return Common.MONITORED_VALUES.getMonitors().stream().sorted(Comparator.comparing(a -> a.getName().translate(user.getTranslations()))).map(ValueMonitorModel::new).collect(Collectors.toList());
}
Aggregations