use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by MangoAutomation.
the class EmailEventHandlerDefinition method handleRoleEvent.
@Override
public void handleRoleEvent(EmailEventHandlerVO 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 update.
@ApiOperation(value = "Update a Role List", notes = "Admin only")
@RequestMapping(method = RequestMethod.PUT, value = "/{xid}")
public ResponseEntity<RoleModel> update(@ApiParam(value = "XID of Role to update", required = true, allowMultiple = false) @PathVariable String xid, @ApiParam(value = "Role List of update", required = true, allowMultiple = false) @RequestBody RoleModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
RoleVO vo = service.update(xid, 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.OK);
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-modules-public by infiniteautomation.
the class RoleRestController method partialUpdate.
@ApiOperation(value = "Partially update a Role", notes = "Admin only")
@RequestMapping(method = RequestMethod.PATCH, value = "/{xid}")
public ResponseEntity<RoleModel> partialUpdate(@PathVariable String xid, @ApiParam(value = "Updated role", required = true) @PatchVORequestBody(service = RoleService.class, modelClass = RoleModel.class) RoleModel model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
RoleVO vo = service.update(xid, 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.OK);
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-modules-public by infiniteautomation.
the class RoleModelMapping method map.
@Override
public RoleModel map(Object from, PermissionHolder user, RestModelMapper mapper) {
RoleVO role = (RoleVO) from;
RoleModel model = new RoleModel(role);
if (role.getInherited() != null) {
Set<String> inherited = new HashSet<>(role.getInherited().size());
model.setInherited(inherited);
for (Role inheritedRole : role.getInherited()) {
inherited.add(inheritedRole.getXid());
}
}
return model;
}
use of com.serotonin.m2m2.vo.role.RoleVO in project ma-core-public by infiniteautomation.
the class RoleDao method saveRelationalData.
@Override
public void saveRelationalData(RoleVO existing, RoleVO vo) {
if (existing != null) {
// Drop the mappings
this.create.deleteFrom(RoleInheritance.ROLE_INHERITANCE).where(RoleInheritance.ROLE_INHERITANCE.roleId.eq(vo.getId())).execute();
}
if (vo.getInherited() != null && vo.getInherited().size() > 0) {
List<Query> inserts = new ArrayList<>();
for (Role role : vo.getInherited()) {
inserts.add(DSL.insertInto(RoleInheritance.ROLE_INHERITANCE).columns(RoleInheritance.ROLE_INHERITANCE.roleId, RoleInheritance.ROLE_INHERITANCE.inheritedRoleId).values(vo.getId(), role.getId()));
}
create.batch(inserts).execute();
}
}
Aggregations