Search in sources :

Example 66 with MangoPermission

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

the class DataPointServiceTest method testSetRolesCannotBeNull.

@Test
@ExpectValidationException("setPermission")
public void testSetRolesCannotBeNull() {
    DataPointVO vo = newVO(editUser);
    setReadPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
    setEditPermission(MangoPermission.requireAnyRole(roleService.getUserRole()), vo);
    vo.setSetPermission(null);
    service.insert(vo);
    runAs.runAs(readUser, () -> {
        DataPointVO fromDb = service.get(vo.getId());
        assertVoEqual(vo, fromDb);
        fromDb.setName("read user edited me");
        fromDb.setSetPermission(new MangoPermission());
        service.update(fromDb.getXid(), fromDb);
    });
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) Test(org.junit.Test) ExpectValidationException(com.infiniteautomation.mango.rules.ExpectValidationException)

Example 67 with MangoPermission

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

the class DataPointServiceTest method addRoleToCreatePermission.

void addRoleToCreatePermission(Role role, DataPointVO vo) {
    DataSourceVO ds = dataSourceService.get(vo.getDataSourceId());
    Set<Set<Role>> roles = new HashSet<>(ds.getEditPermission().getRoles());
    Set<Role> createRole = new HashSet<>();
    createRole.add(role);
    roles.add(createRole);
    ds.setEditPermission(new MangoPermission(roles));
    dataSourceService.update(ds.getXid(), ds);
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) Role(com.serotonin.m2m2.vo.role.Role) HashSet(java.util.HashSet) Set(java.util.Set) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet)

Example 68 with MangoPermission

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

the class EmailEventHandlerServiceTest method addRoleToCreatePermission.

void addRoleToCreatePermission(Role vo) {
    PermissionDefinition def = ModuleRegistry.getPermissionDefinition(EventHandlerCreatePermission.PERMISSION);
    Set<Set<Role>> roleSet = def.getPermission().getRoles();
    Set<Set<Role>> newRoles = new HashSet<>();
    newRoles.add(Collections.singleton(vo));
    for (Set<Role> roles : roleSet) {
        newRoles.add(new HashSet<>(roles));
    }
    Common.getBean(SystemPermissionService.class).update(new MangoPermission(newRoles), def);
}
Also used : Role(com.serotonin.m2m2.vo.role.Role) PermissionDefinition(com.serotonin.m2m2.module.PermissionDefinition) HashSet(java.util.HashSet) Set(java.util.Set) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) HashSet(java.util.HashSet)

Example 69 with MangoPermission

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

the class MangoPermissionConverter method jsonWrite.

@Override
public JsonValue jsonWrite(JsonTypeWriter writer, Object value) throws JsonException {
    MangoPermission permission = (MangoPermission) value;
    JsonArray outerRolesArray = new JsonArray();
    for (Set<Role> roleSet : permission.getRoles()) {
        JsonArray roles = new JsonArray();
        for (Role role : roleSet) {
            roles.add(role.getXid());
        }
        outerRolesArray.add(roles);
    }
    return outerRolesArray;
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) Role(com.serotonin.m2m2.vo.role.Role) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission)

Example 70 with MangoPermission

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

the class UserDao method savePreRelationalData.

@Override
public void savePreRelationalData(User existing, User vo) {
    super.savePreRelationalData(existing, vo);
    MangoPermission readPermission = permissionService.findOrCreate(vo.getReadPermission());
    vo.setReadPermission(readPermission);
    MangoPermission editPermission = permissionService.findOrCreate(vo.getEditPermission());
    vo.setEditPermission(editPermission);
}
Also used : 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