use of com.serotonin.m2m2.vo.role.Role 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.Role in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerServiceTest 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);
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerServiceTest method createDataSource.
MockDataSourceVO createDataSource(Set<Role> editRoles) {
MockDataSourceVO dsVo = new MockDataSourceVO();
dsVo.setName("permissions_test_datasource");
dsVo.setEditPermission(MangoPermission.requireAnyRole(editRoles));
getService();
return (MockDataSourceVO) dataSourceService.insert(dsVo);
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class MailingListServiceTest method testAddMissingEditRole.
@Test
@ExpectValidationException("editPermission")
public void testAddMissingEditRole() {
MailingList vo = newVO(readUser);
Role role = new Role(10000, "new-role");
Set<Role> editRoles = Collections.singleton(role);
vo.setEditPermission(MangoPermission.requireAnyRole(editRoles));
service.insert(vo);
}
use of com.serotonin.m2m2.vo.role.Role in project ma-core-public by infiniteautomation.
the class MailingListServiceTest method testInvalidPermission.
@Test(expected = PermissionException.class)
public void testInvalidPermission() {
MailingList vo = newVO(readUser);
Set<Role> editRoles = Collections.singleton(editRole);
vo.setEditPermission(MangoPermission.requireAnyRole(editRoles));
runAs.runAs(readUser, () -> {
service.insert(vo);
});
}
Aggregations