use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by infiniteautomation.
the class MangoTestBase method createRole.
/**
* Create a role with inherited roles (
*/
protected RoleVO createRole(String xid, String name, Role... inherited) {
RoleService service = Common.getBean(RoleService.class);
RoleVO role = new RoleVO(Common.NEW_ID, xid, name, new HashSet<>(Arrays.asList(inherited)));
return service.insert(role);
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by infiniteautomation.
the class LazyFieldJsonTest method testLazyPermissionFromJsonObject.
@Test
public void testLazyPermissionFromJsonObject() {
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();
LazyField<MangoPermission> permission = new LazyField<>(() -> 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(permission);
writer.setPrettyIndent(0);
writer.setPrettyOutput(true);
writer.writeObject(value);
String json = stringWriter.toString();
JsonTypeReader typeReader = new JsonTypeReader(json);
JsonValue read = typeReader.read();
JsonArray root = read.toJsonArray();
JsonReader reader = new JsonReader(Common.JSON_CONTEXT, root);
ImportContext context = new ImportContext(reader, new ProcessResult(), Common.getTranslations());
LazyField<MangoPermission> readPermission = new LazyField<>();
TypeDefinition lazyType = new TypeDefinition(LazyField.class, MangoPermission.class);
context.getReader().readInto(lazyType, readPermission, root);
assertEquals(permission.get(), readPermission.get());
} 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 PermissionService method loadRoleInheritance.
private RoleInheritance loadRoleInheritance(String xid) {
RoleInheritance i = new RoleInheritance();
RoleVO roleVo = roleDao.getByXid(xid);
if (roleVo == null) {
return null;
}
i.role = roleVo.getRole();
i.inherited = roleDao.getFlatInheritance(roleVo.getRole());
i.inheritedBy = roleDao.getRolesThatInherit(roleVo.getRole());
return i;
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by infiniteautomation.
the class SetPointEventHandlerDefinition method handleRoleEvent.
@Override
public void handleRoleEvent(SetPointEventHandlerVO vo, DaoEvent<? extends RoleVO> event) {
// Remove and re-serialize our handler's script roles if it has a role that was deleted
if (vo.getScriptRoles().getRoles().contains(event.getVo().getRole())) {
switch(event.getType()) {
case UPDATE:
break;
case DELETE:
Set<Role> updated = new HashSet<>(vo.getScriptRoles().getRoles());
updated.remove(event.getVo().getRole());
Set<Role> allRoles = new HashSet<>();
for (Role role : updated) {
allRoles.addAll(service.getAllInheritedRoles(role));
}
ScriptPermissions permission = new ScriptPermissions(allRoles, vo.getScriptRoles().getPermissionHolderName());
vo.setScriptRoles(permission);
eventHandlerService.update(vo.getId(), vo);
break;
default:
break;
}
}
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-modules-public by infiniteautomation.
the class RoleRestController method create.
@ApiOperation(value = "Create a Role", notes = "Admin only")
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<RoleModel> create(@RequestBody RoleModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
RoleVO vo = service.insert(mapping.unmap(model, user, mapper));
URI location = builder.path("/roles/{xid}").buildAndExpand(vo.getXid()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(mapping.map(vo, user, mapper), headers, HttpStatus.CREATED);
}
Aggregations