use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by infiniteautomation.
the class RoleServiceTest method cannotInsertNewUserRole.
@Test
@ExpectValidationException("xid")
public void cannotInsertNewUserRole() {
RoleVO vo = new RoleVO(Common.NEW_ID, PermissionHolder.USER_ROLE_XID, "user default");
service.insert(vo);
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by infiniteautomation.
the class RoleServiceTest method canGetRoleUserHas.
@Test
public void canGetRoleUserHas() {
RoleVO roleUserHas = insertNewVO(readUser);
User testUser = createUser("test-user@example.com", "test-user@example.com", "test-user@example.com", "test-user@example.com", roleUserHas.getRole());
runAs.runAs(testUser, () -> {
RoleVO role = service.get(roleUserHas.getXid());
assertEquals(role.getXid(), roleUserHas.getXid());
assertEquals(role.getName(), roleUserHas.getName());
assertEquals(role.getId(), roleUserHas.getId());
});
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by infiniteautomation.
the class LazyFieldJsonTest method testLazyPermissionInObject.
@Test
public void testLazyPermissionInObject() {
RoleService roleService = Common.getBean(RoleService.class);
PermissionService permissionService = Common.getBean(PermissionService.class);
Role role1 = roleService.insert(new RoleVO(Common.NEW_ID, "XID-1", "Role 1")).getRole();
Role role2 = roleService.insert(new RoleVO(Common.NEW_ID, "XID-2", "Role 2")).getRole();
LazyContainer container = new LazyContainer();
container.supplyPermission(() -> MangoPermission.builder().minterm(role1, role2).build());
try (StringWriter stringWriter = new StringWriter()) {
JsonWriter writer = new JsonWriter(Common.JSON_CONTEXT, stringWriter);
JsonTypeWriter typeWriter = new JsonTypeWriter(Common.JSON_CONTEXT);
JsonValue value = typeWriter.writeObject(container);
writer.setPrettyIndent(0);
writer.setPrettyOutput(true);
writer.writeObject(value);
String json = stringWriter.toString();
JsonTypeReader typeReader = new JsonTypeReader(json);
JsonValue read = typeReader.read();
JsonObject root = read.toJsonObject();
JsonReader reader = new JsonReader(Common.JSON_CONTEXT, root);
ImportContext context = new ImportContext(reader, new ProcessResult(), Common.getTranslations());
LazyContainer readContainer = new LazyContainer();
context.getReader().readInto(readContainer, root);
assertEquals(container.getPermission(), readContainer.getPermission());
} catch (IOException | JsonException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by infiniteautomation.
the class DataSourceRT method handleRoleEvent.
/**
* Override to handle any situations where you need to know that a role was modified.
* be sure to call super for this method as it handles the edit and read permissions
*
* @param event dao event
*/
public void handleRoleEvent(DaoEvent<? extends RoleVO> event) {
if (event.getType() == DaoEventType.DELETE) {
Role deletedRole = event.getVo().getRole();
vo.setEditPermission(vo.getEditPermission().withoutRole(deletedRole));
vo.setReadPermission(vo.getReadPermission().withoutRole(deletedRole));
}
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by infiniteautomation.
the class DataPointService method handleRoleEvent.
@EventListener
protected void handleRoleEvent(DaoEvent<? extends RoleVO> event) {
if (event.getType() == DaoEventType.DELETE) {
Role deletedRole = event.getVo().getRole();
for (DataPointRT rt : getRuntimeManager().getRunningDataPoints()) {
DataPointVO point = rt.getVO();
point.setReadPermission(point.getReadPermission().withoutRole(deletedRole));
point.setEditPermission(point.getEditPermission().withoutRole(deletedRole));
point.setSetPermission(point.getSetPermission().withoutRole(deletedRole));
}
}
}
Aggregations