Search in sources :

Example 81 with MangoPermission

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

the class PermissionDao method get.

/**
 * Get a MangoPermission by id
 * @return permission if found or null
 */
public MangoPermission get(Integer id) {
    // TODO Mango 4.0 improve performance
    // Fist check to see if it exists as it may have no minterms
    Integer foundId = create.select(permissions.id).from(permissions).where(permissions.id.equal(id)).fetchOneInto(Integer.class);
    if (foundId == null) {
        return null;
    }
    Map<Integer, Set<Role>> mintermMap = new HashMap<>();
    create.select(roleTable.id, roleTable.xid, permissionsMinterms.mintermId).from(permissionsMinterms).join(mintermsRoles).on(permissionsMinterms.mintermId.eq(mintermsRoles.mintermId)).join(roleTable).on(roleTable.id.eq(mintermsRoles.roleId)).where(permissionsMinterms.permissionId.eq(id)).orderBy(permissionsMinterms.permissionId.asc(), permissionsMinterms.mintermId.asc()).fetch().forEach(record -> {
        Role role = new Role(record.get(roleTable.id), record.get(roleTable.xid));
        Integer mintermId = record.get(permissionsMinterms.mintermId);
        mintermMap.computeIfAbsent(mintermId, m -> new HashSet<>()).add(role);
    });
    if (mintermMap.size() > 0) {
        Set<Set<Role>> roleSet = new HashSet<>(mintermMap.values());
        return new MangoPermission(roleSet).withId(id);
    }
    return new MangoPermission(id);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) DSL(org.jooq.impl.DSL) Role(com.serotonin.m2m2.vo.role.Role) Minterms(com.infiniteautomation.mango.db.tables.Minterms) TransactionDefinition(org.springframework.transaction.TransactionDefinition) DatabaseProxy(com.serotonin.m2m2.db.DatabaseProxy) Permissions(com.infiniteautomation.mango.db.tables.Permissions) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) MintermsRoles(com.infiniteautomation.mango.db.tables.MintermsRoles) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Map(java.util.Map) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) Repository(org.springframework.stereotype.Repository) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Roles(com.infiniteautomation.mango.db.tables.Roles) PermissionsMinterms(com.infiniteautomation.mango.db.tables.PermissionsMinterms) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet)

Example 82 with MangoPermission

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

the class SystemPermissionDao method update.

/**
 * Update the permission
 */
public void update(String permissionTypeName, MangoPermission existing, MangoPermission permission) {
    if (!existing.equals(permission)) {
        permissionService.deletePermissions(existing);
    }
    MangoPermission toUpdate = permissionService.findOrCreate(permission);
    this.create.update(SYSTEM_PERMISSIONS).set(SYSTEM_PERMISSIONS.permissionId, toUpdate.getId()).where(SYSTEM_PERMISSIONS.permissionType.eq(permissionTypeName)).execute();
}
Also used : MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 83 with MangoPermission

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

the class EventDetectorDao method deletePostRelationalData.

@Override
public void deletePostRelationalData(AbstractEventDetectorVO vo) {
    // Clean permissions
    MangoPermission readPermission = vo.getReadPermission();
    MangoPermission editPermission = vo.getEditPermission();
    permissionService.deletePermissions(readPermission, editPermission);
    vo.getDefinition().deletePostRelationalData(vo);
}
Also used : MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 84 with MangoPermission

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

the class EventDetectorDao method savePreRelationalData.

@Override
public void savePreRelationalData(AbstractEventDetectorVO existing, AbstractEventDetectorVO vo) {
    MangoPermission readPermission = permissionService.findOrCreate(vo.getReadPermission());
    vo.setReadPermission(readPermission);
    MangoPermission editPermission = permissionService.findOrCreate(vo.getEditPermission());
    vo.setEditPermission(editPermission);
    vo.getDefinition().savePreRelationalData(existing, vo);
}
Also used : MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 85 with MangoPermission

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

the class DataSourceDao method mapRecord.

@Override
public DataSourceVO mapRecord(Record record) {
    DataSourceVO ds = (DataSourceVO) SerializationHelper.readObjectInContextFromArray(record.get(table.data));
    ds.setId(record.get(table.id));
    ds.setXid(record.get(table.xid));
    ds.setName(record.get(table.name));
    ds.setDefinition(ModuleRegistry.getDataSourceDefinition(record.get(table.dataSourceType)));
    ds.setData(extractDataFromObject(record.get(table.jsonData)));
    ds.setReadPermission(new MangoPermission(record.get(table.readPermissionId)));
    ds.setEditPermission(new MangoPermission(record.get(table.editPermissionId)));
    return ds;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) 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