use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException 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();
}
use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.
the class AuditRestController method queryRQL.
@ApiOperation(value = "Query Audit Events", notes = "Admin access only", response = AuditEventInstanceModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<PageQueryStream<AuditEventInstanceVO, AuditEventInstanceModel, AuditEventDao>> queryRQL(HttpServletRequest request) {
RestProcessResult<PageQueryStream<AuditEventInstanceVO, AuditEventInstanceModel, AuditEventDao>> result = new RestProcessResult<PageQueryStream<AuditEventInstanceVO, AuditEventInstanceModel, AuditEventDao>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
try {
if (!user.isAdmin()) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
} else {
// Limit our results based on the fact that our permissions should be in the permissions strings
ASTNode root = parseRQLtoAST(request.getQueryString());
return result.createResponseEntity(getPageStream(root));
}
} catch (InvalidRQLRestException e) {
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.
the class DataPointRestController method bulkClearSetPermissions.
@ApiOperation(value = "Bulk Clear Set Permissions", notes = "", response = Long.class)
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/bulk-clear-set-permissions")
public ResponseEntity<Long> bulkClearSetPermissions(HttpServletRequest request) {
RestProcessResult<Long> result = new RestProcessResult<Long>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (!user.isAdmin()) {
LOG.warn("User " + user.getUsername() + " attempted to clear bulk permissions");
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
try {
ASTNode node = parseRQLtoAST(request.getQueryString());
long changed = this.dao.bulkClearPermissions(node, true);
return result.createResponseEntity(changed);
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.
the class DataPointRestController method bulkClearReadPermissions.
@ApiOperation(value = "Bulk Clear Read Permissions", notes = "", response = Long.class)
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/bulk-clear-read-permissions")
public ResponseEntity<Long> bulkClearReadPermissions(HttpServletRequest request) {
RestProcessResult<Long> result = new RestProcessResult<Long>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (!user.isAdmin()) {
LOG.warn("User " + user.getUsername() + " attempted to clear bulk permissions");
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
try {
ASTNode node = parseRQLtoAST(request.getQueryString());
long changed = this.dao.bulkClearPermissions(node, false);
return result.createResponseEntity(changed);
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException in project ma-modules-public by infiniteautomation.
the class DataPointRestController method bulkApplySetPermissions.
@ApiOperation(value = "Bulk Update Set Permissions", notes = "", response = Long.class)
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/bulk-apply-set-permissions")
public ResponseEntity<Long> bulkApplySetPermissions(@ApiParam(value = "Permissions", required = true) @RequestBody(required = true) String permissions, HttpServletRequest request) {
RestProcessResult<Long> result = new RestProcessResult<Long>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (!user.isAdmin()) {
LOG.warn("User " + user.getUsername() + " attempted to set bulk permissions");
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
try {
ASTNode node = parseRQLtoAST(request.getQueryString());
long changed = this.dao.bulkUpdatePermissions(node, permissions, true);
return result.createResponseEntity(changed);
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
Aggregations