use of com.infiniteautomation.mango.rest.latest.model.user.UserModel in project ma-modules-public by infiniteautomation.
the class UserRestController method patchUser.
@ApiOperation(value = "Partially update a User", notes = "Admin or Patch Self only", response = UserModel.class)
@RequestMapping(method = RequestMethod.PATCH, value = "/{username}")
public ResponseEntity<UserModel> patchUser(@PathVariable String username, @ApiParam(value = "User", required = true) @PatchVORequestBody(service = UsersService.class, modelClass = UserModel.class, idType = PatchIdField.OTHER, urlPathVariableName = "username") UserModel model, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request, UriComponentsBuilder builder, Authentication authentication) {
User existing = service.get(username);
User currentUser = user.getUser();
if (currentUser != null && existing.getId() == currentUser.getId() && !(authentication instanceof UsernamePasswordAuthenticationToken))
throw new PermissionException(new TranslatableMessage("rest.error.usernamePasswordOnly"), user);
User update = service.update(existing.getId(), model.toVO());
sessionRegistry.userUpdated(request, update);
URI location = builder.path("/users/{username}").buildAndExpand(update.getUsername()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(new UserModel(update), headers, HttpStatus.OK);
}
use of com.infiniteautomation.mango.rest.latest.model.user.UserModel in project ma-modules-public by infiniteautomation.
the class UserRestController method createUser.
@ApiOperation(value = "Create User", notes = "Superadmin permission required", response = UserModel.class)
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<UserModel> createUser(@ApiParam(value = "User", required = true) @RequestBody UserModel model, UriComponentsBuilder builder) {
User newUser = service.insert(model.toVO());
URI location = builder.path("/users/{username}").buildAndExpand(newUser.getUsername()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(new UserModel(newUser), headers, HttpStatus.OK);
}
use of com.infiniteautomation.mango.rest.latest.model.user.UserModel in project ma-modules-public by infiniteautomation.
the class UserRestController method updateMuted.
@ApiOperation(value = "Update a user's audio mute setting", notes = "If you do not provide the mute parameter the current setting will be toggled")
@RequestMapping(method = RequestMethod.PUT, value = "/{username}/mute")
public ResponseEntity<UserModel> updateMuted(@ApiParam(value = "Username", required = true) @PathVariable String username, @ApiParam(value = "Mute", defaultValue = "Toggle the current setting") @RequestParam(required = false) Boolean mute, HttpServletRequest request, UriComponentsBuilder builder, @AuthenticationPrincipal PermissionHolder user, Authentication authentication) {
User update = service.get(username);
User currentUser = user.getUser();
if (currentUser != null && update.getId() == currentUser.getId() && !(authentication instanceof UsernamePasswordAuthenticationToken))
throw new PermissionException(new TranslatableMessage("rest.error.usernamePasswordOnly"), user);
if (mute == null) {
update.setMuted(!update.isMuted());
} else {
update.setMuted(mute);
}
update = service.update(username, update);
sessionRegistry.userUpdated(request, update);
URI location = builder.path("/users/{username}").buildAndExpand(update.getUsername()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(new UserModel(update), headers, HttpStatus.OK);
}
use of com.infiniteautomation.mango.rest.latest.model.user.UserModel in project ma-modules-public by infiniteautomation.
the class SystemEventTypeModelMapping method map.
@Override
public SystemEventTypeModel map(Object from, PermissionHolder user, RestModelMapper mapper) {
SystemEventType type = (SystemEventType) from;
if (StringUtils.equals(SystemEventType.TYPE_USER_LOGIN, type.getEventSubtype())) {
UserModel userModel = null;
User u = UserDao.getInstance().get(type.getReferenceId1());
if (u != null)
userModel = new UserModel(u);
return new SystemEventTypeModel(type, userModel);
} else
return new SystemEventTypeModel(type);
}
Aggregations