Search in sources :

Example 31 with MangoPermission

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

the class EventInstanceDao method deletePostRelationalData.

@Override
public void deletePostRelationalData(EventInstanceVO vo) {
    MangoPermission readPermission = vo.getReadPermission();
    permissionService.deletePermissions(readPermission);
}
Also used : MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 32 with MangoPermission

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

the class MailingListDao method mapRecord.

@Override
public MailingList mapRecord(Record record) {
    MailingList ml = new MailingList();
    ml.setId(record.get(table.id));
    ml.setXid(record.get(table.xid));
    ml.setName(record.get(table.name));
    ml.setReceiveAlarmEmails(AlarmLevels.fromValue(record.get(table.receiveAlarmEmails)));
    ml.setReadPermission(new MangoPermission(record.get(table.readPermissionId)));
    ml.setEditPermission(new MangoPermission(record.get(table.editPermissionId)));
    return ml;
}
Also used : MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 33 with MangoPermission

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

the class SystemPermissionDao method insert.

/**
 * Update the permission
 */
public void insert(String permissionTypeName, MangoPermission permission) {
    MangoPermission toInsert = permissionService.findOrCreate(permission);
    this.create.insertInto(SYSTEM_PERMISSIONS).columns(SYSTEM_PERMISSIONS.permissionId, SYSTEM_PERMISSIONS.permissionType).values(toInsert.getId(), permissionTypeName).execute();
}
Also used : MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 34 with MangoPermission

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

the class Upgrade29 method convertDataSources.

private void convertDataSources(OutputStream out) {
    Map<String, String[]> scripts = new HashMap<>();
    scripts.put(DatabaseType.MYSQL.name(), dataSourcePermissionMySQL);
    scripts.put(DatabaseType.H2.name(), dataSourcePermissionH2);
    scripts.put(DatabaseType.MSSQL.name(), dataSourcePermissionMSSQL);
    scripts.put(DatabaseType.POSTGRES.name(), dataSourcePermissionMySQL);
    runScript(scripts, out);
    // Move current permissions to roles
    ejt.query("SELECT id, editPermission FROM dataSources", rs -> {
        int voId = rs.getInt(1);
        // Add role/mapping
        MangoPermission editPermissions = PermissionMigration.parseLegacyPermission(rs.getString(2));
        Integer edit = getOrCreatePermission(editPermissions).getId();
        ejt.update("UPDATE dataSources SET editPermissionId=?,readPermissionId=? WHERE id=?", edit, edit, voId);
    });
    // Restrict to NOT NULL
    scripts = new HashMap<>();
    scripts.put(DatabaseType.MYSQL.name(), dataSourcePermissionNotNullMySQL);
    scripts.put(DatabaseType.H2.name(), dataSourcePermissionNotNull);
    scripts.put(DatabaseType.MSSQL.name(), dataSourcePermissionNotNull);
    scripts.put(DatabaseType.POSTGRES.name(), dataSourcePermissionNotNull);
    runScript(scripts, out);
    // Drop columns
    scripts = new HashMap<>();
    scripts.put(DatabaseType.MYSQL.name(), dataSourcesMySQL);
    scripts.put(DatabaseType.H2.name(), dataSourcesH2);
    scripts.put(DatabaseType.MSSQL.name(), dataSourcesMSSQL);
    scripts.put(DatabaseType.POSTGRES.name(), dataSourcesMySQL);
    runScript(scripts, out);
}
Also used : HashMap(java.util.HashMap) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 35 with MangoPermission

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

the class Upgrade29 method convertDataPoints.

/**
 * Convert data points AFTER data sources so we can reference the readPermissionId and editPermissionId
 */
private void convertDataPoints(OutputStream out) {
    // Create permission columns
    Map<String, String[]> scripts = new HashMap<>();
    scripts.put(DatabaseType.MYSQL.name(), dataPointPermissionMySQL);
    scripts.put(DatabaseType.H2.name(), dataPointPermissionH2);
    scripts.put(DatabaseType.MSSQL.name(), dataPointPermissionMSSQL);
    scripts.put(DatabaseType.POSTGRES.name(), dataPointPermissionMySQL);
    runScript(scripts, out);
    // Move current permissions to roles
    ejt.query("SELECT dp.id, dp.readPermission, dp.setPermission, ds.editPermissionId " + "FROM dataPoints AS dp LEFT JOIN dataSources AS ds ON dp.dataSourceId = ds.id", rs -> {
        int voId = rs.getInt(1);
        // Add role/mapping
        MangoPermission readPermissions = PermissionMigration.parseLegacyPermission(rs.getString(2));
        Integer read = getOrCreatePermission(readPermissions).getId();
        MangoPermission setPermissions = PermissionMigration.parseLegacyPermission(rs.getString(3));
        Integer set = getOrCreatePermission(setPermissions).getId();
        int edit = rs.getInt(4);
        if (edit == 0)
            throw new IllegalStateException("dataSource.editPermissionId was null for dataPoint.id " + voId);
        ejt.update("UPDATE dataPoints SET readPermissionId=?,editPermissionId=?,setPermissionId=? WHERE id=?", read, edit, set, voId);
    });
    // Restrict to NOT NULL
    scripts = new HashMap<>();
    scripts.put(DatabaseType.MYSQL.name(), dataPointPermissionNotNullMySQL);
    scripts.put(DatabaseType.H2.name(), dataPointPermissionNotNull);
    scripts.put(DatabaseType.MSSQL.name(), dataPointPermissionNotNull);
    scripts.put(DatabaseType.POSTGRES.name(), dataPointPermissionNotNull);
    runScript(scripts, out);
    scripts = new HashMap<>();
    scripts.put(DatabaseType.MYSQL.name(), dataPointsMySQL);
    scripts.put(DatabaseType.H2.name(), dataPointsH2);
    scripts.put(DatabaseType.MSSQL.name(), dataPointsMSSQL);
    scripts.put(DatabaseType.POSTGRES.name(), dataPointsMySQL);
    runScript(scripts, out);
}
Also used : HashMap(java.util.HashMap) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Aggregations

MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)93 Role (com.serotonin.m2m2.vo.role.Role)22 HashSet (java.util.HashSet)21 Set (java.util.Set)18 HashMap (java.util.HashMap)13 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)12 PermissionDefinition (com.serotonin.m2m2.module.PermissionDefinition)11 JsonException (com.serotonin.json.JsonException)10 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)9 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)8 JsonValue (com.serotonin.json.type.JsonValue)7 ArrayList (java.util.ArrayList)7 JsonArray (com.serotonin.json.type.JsonArray)6 JsonObject (com.serotonin.json.type.JsonObject)6 User (com.serotonin.m2m2.vo.User)6 OutputStream (java.io.OutputStream)5 Test (org.junit.Test)5 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 IOException (java.io.IOException)4 ResultSet (java.sql.ResultSet)4