use of com.serotonin.m2m2.vo.permission.Permissions in project ma-modules-public by infiniteautomation.
the class EventHandlerRestController method get.
@ApiOperation(value = "Get EventHandler by XID", notes = "EventType permission required")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "application/sero-json" }, value = "/{xid}")
public ResponseEntity<AbstractEventHandlerModel<?>> get(@ApiParam(value = "Valid Eventh Handler XID", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<AbstractEventHandlerModel<?>> result = new RestProcessResult<AbstractEventHandlerModel<?>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
AbstractEventHandlerVO<?> vo = EventHandlerDao.instance.getByXid(xid);
if (vo == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
} else {
// Check Permissions
if (Permissions.hasAdmin(user))
return result.createResponseEntity(vo.asModel());
else
result.addRestMessage(HttpStatus.UNAUTHORIZED, new TranslatableMessage("permissions.accessDenied", user.getUsername(), SuperadminPermissionDefinition.GROUP_NAME));
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-modules-public by infiniteautomation.
the class JsonDataRestController method getPublicData.
@ApiOperation(value = "Get Public JSON Data", notes = "Returns only the data")
@RequestMapping(method = RequestMethod.GET, value = "/public/{xid}")
public ResponseEntity<JsonDataModel> getPublicData(HttpServletRequest request, @ApiParam(value = "XID", required = true, allowMultiple = false) @PathVariable String xid) {
RestProcessResult<JsonDataModel> result = new RestProcessResult<JsonDataModel>(HttpStatus.OK);
JsonDataVO vo = JsonDataDao.instance.getByXid(xid);
if (vo == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
} else {
// Check existing permissions
if (!vo.isPublicData()) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
} else {
return result.createResponseEntity(new JsonDataModel(vo));
}
}
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-modules-public by infiniteautomation.
the class JsonDataRestController method getDataWithPath.
@ApiOperation(value = "Get JSON Data using a path", notes = "To get a sub component of the data use a path of member.submember")
@RequestMapping(method = RequestMethod.GET, value = "/{xid}/{path:.*}")
public ResponseEntity<JsonDataModel> getDataWithPath(HttpServletRequest request, @ApiParam(value = "XID", required = true, allowMultiple = false) @PathVariable String xid, @ApiParam(value = "Data path using dots as separator", required = true, allowMultiple = false) @PathVariable String path) throws UnsupportedEncodingException {
RestProcessResult<JsonDataModel> result = new RestProcessResult<JsonDataModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
JsonDataVO vo = JsonDataDao.instance.getByXid(xid);
if (vo == null) {
result.addRestMessage(getDoesNotExistMessage());
} else {
// Check existing permissions
if (!Permissions.hasPermission(user, vo.getReadPermission())) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
String[] pathParts = splitAndDecodePath(path);
if (pathParts.length == 0) {
return result.createResponseEntity(new JsonDataModel(vo));
} else {
JsonNode data = (JsonNode) vo.getJsonData();
JsonNode subNode = getNode(data, pathParts);
vo.setJsonData(subNode);
return result.createResponseEntity(new JsonDataModel(vo));
}
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-modules-public by infiniteautomation.
the class JsonDataRestController method deletePartialJsonData.
@ApiOperation(value = "Partially Delete JSON Data", notes = "{path} is the path to data with dots data.member.submember", response = JsonDataModel.class)
@ApiResponses({ @ApiResponse(code = 201, message = "Data Deleted", response = JsonDataModel.class), @ApiResponse(code = 401, message = "Unauthorized Access", response = ResponseEntity.class), @ApiResponse(code = 403, message = "Data Doesn't Exists") })
@RequestMapping(method = RequestMethod.DELETE, value = "/{xid}/{path:.*}")
public ResponseEntity<JsonDataModel> deletePartialJsonData(@ApiParam(value = "XID", required = true, allowMultiple = false) @PathVariable String xid, @ApiParam(value = "Data path using dots as separator", required = true, allowMultiple = false) @PathVariable String path, UriComponentsBuilder builder, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<JsonDataModel> result = new RestProcessResult<JsonDataModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
JsonDataVO vo = this.dao.getByXid(xid);
if (vo != null) {
// Check existing permissions
if (!Permissions.hasPermission(user, vo.getEditPermission())) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
JsonDataModel model = new JsonDataModel(vo);
String[] pathParts;
if (path == null || (pathParts = path.split("\\.")).length == 0) {
// Delete the whole thing
this.dao.delete(vo.getId());
} else {
// Delete something from the map
JsonNode existingData = (JsonNode) vo.getJsonData();
boolean deleted = deleteNode(existingData, pathParts);
if (!deleted) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
if (!model.validate()) {
result.addRestMessage(this.getValidationFailedError());
return result.createResponseEntity(model);
}
try {
String initiatorId = request.getHeader("initiatorId");
this.dao.save(vo, initiatorId);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
}
}
return result.createResponseEntity(model);
} else {
result.addRestMessage(getDoesNotExistMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.permission.Permissions in project ma-modules-public by infiniteautomation.
the class JsonDataRestController method list.
@ApiOperation(value = "List all available xids", notes = "Shows any xids that you have read permissions for", response = List.class)
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<String>> list(HttpServletRequest request) {
RestProcessResult<List<String>> result = new RestProcessResult<List<String>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
List<JsonDataVO> all = this.dao.getAll();
List<String> available = new ArrayList<String>();
for (JsonDataVO vo : all) {
// Check existing permissions
if (Permissions.hasPermission(user, vo.getReadPermission())) {
available.add(vo.getXid());
}
}
return result.createResponseEntity(available);
}
return result.createResponseEntity();
}
Aggregations