use of com.wordnik.swagger.annotations.ApiOperation in project ma-modules-public by infiniteautomation.
the class UserRestController method getNewUser.
@ApiOperation(value = "Get new user", notes = "Returns a new user with default values")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/new/user")
public ResponseEntity<UserModel> getNewUser(HttpServletRequest request) {
RestProcessResult<UserModel> result = new RestProcessResult<UserModel>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
return result.createResponseEntity(new UserModel(new User()));
}
return result.createResponseEntity();
}
use of com.wordnik.swagger.annotations.ApiOperation 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, produces = { "application/json", "text/csv" }, value = "/{username}/mute")
public ResponseEntity<UserModel> updateMuted(@ApiParam(value = "Username", required = true, allowMultiple = false) @PathVariable String username, @ApiParam(value = "Mute", required = false, defaultValue = "Toggle the current setting", allowMultiple = false) @RequestParam(required = false) Boolean mute, HttpServletRequest request, Authentication authentication) throws RestValidationFailedException {
RestProcessResult<UserModel> result = new RestProcessResult<UserModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
User u = UserDao.instance.getUser(username);
if (Permissions.hasAdmin(user)) {
if (u == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
if (u.getId() == user.getId() && !(authentication instanceof UsernamePasswordAuthenticationToken)) {
throw new AccessDeniedException(new TranslatableMessage("rest.error.usernamePasswordOnly"));
}
if (mute == null) {
u.setMuted(!u.isMuted());
} else {
u.setMuted(mute);
}
UserModel model = new UserModel(u);
if (!model.validate()) {
result.addRestMessage(this.getValidationFailedError());
} else {
UserDao.instance.saveUser(u);
sessionRegistry.userUpdated(request, u);
}
return result.createResponseEntity(model);
} else {
if (u.getId() != user.getId()) {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to access user : " + u.getUsername());
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
} else {
if (mute == null) {
// Toggle
u.setMuted(!u.isMuted());
} else {
u.setMuted(mute);
}
UserModel model = new UserModel(u);
// Allow users to update themselves
model.getData().setId(u.getId());
if (!model.validate()) {
result.addRestMessage(this.getValidationFailedError());
} else {
UserDao.instance.saveUser(u);
sessionRegistry.userUpdated(request, u);
}
return result.createResponseEntity(model);
}
}
}
return result.createResponseEntity();
}
use of com.wordnik.swagger.annotations.ApiOperation in project ma-modules-public by infiniteautomation.
the class UserRestController method getUser.
@ApiOperation(value = "Get user by name", notes = "Returns the user specified by the given username")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/{username}")
public ResponseEntity<UserModel> getUser(@ApiParam(value = "Valid username", required = true, allowMultiple = false) @PathVariable String username, HttpServletRequest request) {
RestProcessResult<UserModel> result = new RestProcessResult<UserModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
User u = UserDao.instance.getUser(username);
if (Permissions.hasAdmin(user)) {
if (u == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
UserModel model = new UserModel(u);
return result.createResponseEntity(model);
} else {
if (u.getId() != user.getId()) {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to access user : " + u.getUsername());
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
} else {
// Allow users to access themselves
return result.createResponseEntity(new UserModel(u));
}
}
}
return result.createResponseEntity();
}
use of com.wordnik.swagger.annotations.ApiOperation in project ma-modules-public by infiniteautomation.
the class UserRestController method getCurrentUser.
@ApiOperation(value = "Get current user", notes = "Returns the logged in user")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/current")
public ResponseEntity<UserModel> getCurrentUser(HttpServletRequest request) {
RestProcessResult<UserModel> result = new RestProcessResult<UserModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
UserModel model = new UserModel(user);
return result.createResponseEntity(model);
}
return result.createResponseEntity();
}
use of com.wordnik.swagger.annotations.ApiOperation in project ma-modules-public by infiniteautomation.
the class UserRestController method queryRQL.
@ApiOperation(value = "Query Users", notes = "", response = UserModel.class, responseContainer = "Array")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Ok", response = UserModel.class), @ApiResponse(code = 403, message = "User does not have access", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<QueryDataPageStream<User>> queryRQL(HttpServletRequest request) {
RestProcessResult<QueryDataPageStream<User>> result = new RestProcessResult<QueryDataPageStream<User>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
try {
// Parse the RQL Query
ASTNode query = parseRQLtoAST(request.getQueryString());
if (!user.isAdmin()) {
query = addAndRestriction(query, new ASTNode("eq", "id", user.getId()));
}
return result.createResponseEntity(getPageStream(query));
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
Aggregations