Search in sources :

Example 6 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-modules-public by infiniteautomation.

the class AbstractDataSourceModel method toVO.

@Override
public T toVO() {
    T vo = super.toVO();
    vo.setEnabled(enabled);
    if (eventAlarmLevels != null) {
        for (EventTypeAlarmLevelModel eval : eventAlarmLevels) {
            vo.setAlarmLevel(eval.getEventType(), eval.getLevel());
        }
    }
    if (purgeSettings != null)
        purgeSettings.toVO(vo);
    vo.setEditPermission(editPermission != null ? editPermission.getPermission() : new MangoPermission());
    vo.setReadPermission(readPermission != null ? readPermission.getPermission() : new MangoPermission());
    vo.setData(data);
    return vo;
}
Also used : DataSourceRT(com.serotonin.m2m2.rt.dataSource.DataSourceRT) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 7 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-modules-public by infiniteautomation.

the class JsonDataModel method toVO.

@Override
public JsonDataVO toVO() throws ValidationException {
    JsonDataVO vo = super.toVO();
    vo.setReadPermission(readPermission != null ? readPermission.getPermission() : new MangoPermission());
    vo.setEditPermission(editPermission != null ? editPermission.getPermission() : new MangoPermission());
    vo.setJsonData(jsonData);
    return vo;
}
Also used : JsonDataVO(com.serotonin.m2m2.vo.json.JsonDataVO) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 8 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-modules-public by infiniteautomation.

the class WatchListDao method mapRecord.

@Override
public WatchListVO mapRecord(Record record) {
    WatchListVO wl = new WatchListVO();
    wl.setId(record.get(table.id));
    wl.setXid(record.get(table.xid));
    wl.setName(record.get(table.name));
    String type = record.get(table.type);
    if (type != null) {
        wl.setType(WatchListType.valueOf(type.toUpperCase(Locale.ROOT)));
    }
    // Read the data
    try {
        String c = record.get(table.data);
        if (c != null) {
            WatchListDbDataModel data = getObjectReader(WatchListDbDataModel.class).readValue(c);
            if (data != null) {
                wl.setQuery(data.query);
                wl.setParams(data.params);
                wl.setData(data.data);
            }
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
    wl.setReadPermission(new MangoPermission(record.get(table.readPermissionId)));
    wl.setEditPermission(new MangoPermission(record.get(table.editPermissionId)));
    return wl;
}
Also used : ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO)

Example 9 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-modules-public by infiniteautomation.

the class WatchListModelMapping method unmap.

@Override
public WatchListVO unmap(Object from, PermissionHolder user, RestModelMapper mapper) throws ValidationException {
    WatchListModel model = (WatchListModel) from;
    WatchListVO vo = model.toVO();
    vo.setReadPermission(model.getReadPermission() != null ? model.getReadPermission().getPermission() : new MangoPermission());
    vo.setEditPermission(model.getEditPermission() != null ? model.getEditPermission().getPermission() : new MangoPermission());
    if (vo.getType() == WatchListType.STATIC && model.getPoints() != null) {
        vo.setPointList(model.getPoints().stream().map(m -> {
            DataPointSummary summary = new DataPointSummary();
            summary.setXid(m.getXid());
            return summary;
        }).collect(Collectors.toList()));
    }
    return vo;
}
Also used : DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) WatchListVO(com.serotonin.m2m2.watchlist.WatchListVO)

Example 10 with MangoPermission

use of com.infiniteautomation.mango.permission.MangoPermission in project ma-modules-public by infiniteautomation.

the class Upgrade6 method upgrade.

@Override
protected void upgrade() throws Exception {
    OutputStream out = createUpdateLogOutputStream();
    // First drop any watch lists of type 'hierarhcy'
    ejt.update("DELETE FROM watchLists WHERE type='hierarchy'");
    // 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, readPermission, editPermission FROM watchLists", rs -> {
        int voId = rs.getInt(1);
        // Add role/mapping
        MangoPermission readPermissions = PermissionMigration.parseLegacyPermission(rs.getString(2));
        Integer read = getOrCreatePermission(readPermissions).getId();
        MangoPermission editPermissions = PermissionMigration.parseLegacyPermission(rs.getString(3));
        Integer edit = getOrCreatePermission(editPermissions).getId();
        ejt.update("UPDATE watchLists SET readPermissionId=?, editPermissionId=? WHERE id=?", read, edit, 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<>();
    scripts.put(DatabaseType.MYSQL.name(), sql);
    scripts.put(DatabaseType.H2.name(), sql);
    scripts.put(DatabaseType.MSSQL.name(), sql);
    scripts.put(DatabaseType.POSTGRES.name(), sql);
    runScript(scripts, out);
}
Also used : HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Aggregations

MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)163 Role (com.serotonin.m2m2.vo.role.Role)38 HashSet (java.util.HashSet)35 Set (java.util.Set)32 HashMap (java.util.HashMap)23 PermissionDefinition (com.serotonin.m2m2.module.PermissionDefinition)21 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)19 JsonException (com.serotonin.json.JsonException)18 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)15 JsonValue (com.serotonin.json.type.JsonValue)13 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)13 JsonArray (com.serotonin.json.type.JsonArray)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 User (com.serotonin.m2m2.vo.User)9 JsonObject (com.serotonin.json.type.JsonObject)8 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)7 ResultSet (java.sql.ResultSet)7 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6