use of com.serotonin.m2m2.vo.FileStore in project ma-modules-public by infiniteautomation.
the class UserFileStoresRestController method updateUserFileStore.
@ApiOperation(value = "Update a user file store")
@RequestMapping(method = RequestMethod.PUT, value = "/{xid}")
public ResponseEntity<FileStoreModel> updateUserFileStore(@ApiParam(value = "File store XID", required = true) @PathVariable("xid") String xid, @ApiParam(value = "Updated file store", required = true) @RequestBody FileStoreModel fileStore, UriComponentsBuilder builder) {
FileStore updated = this.fileStoreService.update(xid, fileStore.toVO());
URI location = builder.path("/user-file-stores/{xid}").buildAndExpand(updated.getXid()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(new FileStoreModel(updated), headers, HttpStatus.OK);
}
use of com.serotonin.m2m2.vo.FileStore in project ma-modules-public by infiniteautomation.
the class UserFileStoresRestController method getUserFileStoreModel.
@ApiOperation(value = "Get a user file store model")
@RequestMapping(method = RequestMethod.GET, value = "/{xid}")
public MappingJacksonValue getUserFileStoreModel(@PathVariable("xid") String xid, @AuthenticationPrincipal PermissionHolder user) {
FileStore fs = this.fileStoreService.get(xid);
// Seeing the permissions fields should require write protection
MappingJacksonValue resultWithView = new MappingJacksonValue(new FileStoreModel(fs));
if (fileStoreService.hasEditPermission(user, fs)) {
resultWithView.setSerializationView(RoleViews.ShowRoles.class);
} else {
resultWithView.setSerializationView(Object.class);
}
return resultWithView;
}
use of com.serotonin.m2m2.vo.FileStore in project ma-core-public by infiniteautomation.
the class FileStoreDao method mapRecord.
@Override
public FileStore mapRecord(Record record) {
FileStore result = new FileStore();
result.setId(record.get(table.id));
result.setXid(record.get(table.xid));
result.setName(record.get(table.name));
result.setReadPermission(new MangoPermission(record.get(table.readPermissionId)));
result.setWritePermission(new MangoPermission(record.get(table.writePermissionId)));
return result;
}
use of com.serotonin.m2m2.vo.FileStore in project ma-core-public by infiniteautomation.
the class NashornScriptEngineDefinition method createEngine.
@Override
public ScriptEngine createEngine(ScriptEngineFactory engineFactory, MangoScript script) {
ScriptEngine engine = createScriptEngine(engineFactory, permissionService.hasAdminRole(script) ? null : c -> false);
Bindings engineBindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
Object originalLoad = engineBindings.get("load");
if (!permissionService.hasAdminRole(script)) {
// remove exit and quit functions from bindings
for (String key : KEYS_TO_REMOVE) {
engineBindings.remove(key);
}
// make the engine and context inaccessible
try {
engine.eval("Object.defineProperty(this, 'engine', {}); Object.defineProperty(this, 'context', {});");
} catch (ScriptException e) {
throw new RuntimeException(e);
}
}
Function<Object, Object> replacementLoad = source -> {
URL url = null;
if (source instanceof URL) {
url = (URL) source;
} else if (source instanceof String && ((String) source).indexOf(':') >= 0) {
try {
url = new URL((String) source);
} catch (MalformedURLException e) {
// ignore
}
}
if (url != null) {
String protocol = url.getProtocol();
boolean isFileStore = "filestore".equals(protocol);
boolean isWeb = "http".equals(protocol) || "https".equals(protocol);
if (isFileStore && permissionService.hasPermission(script, loadFileStorePermission.getPermission()) || isWeb && permissionService.hasPermission(script, loadWebPermission.getPermission())) {
return callFunction(originalLoad, null, source);
}
}
permissionService.ensurePermission(script, loadOtherPermission.getPermission());
return callFunction(originalLoad, null, source);
};
engineBindings.put("load", replacementLoad);
return engine;
}
use of com.serotonin.m2m2.vo.FileStore in project ma-core-public by infiniteautomation.
the class FileStoreServiceTest method updateVO.
@Override
FileStore updateVO(FileStore existing) {
FileStore edit = new FileStore();
edit.setId(existing.getId());
edit.setXid("new store name");
edit.setName(edit.getXid());
return edit;
}
Aggregations