implemented file deletion

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-02 00:55:57 +02:00
parent 7284637057
commit 20d0247c90
2 changed files with 4 additions and 9 deletions

View File

@@ -92,10 +92,7 @@ public class FileModule extends BaseHandler implements FileService {
var filename = "/company/"+cid; var filename = "/company/"+cid;
if (!path.empty()) filename += "/"+URLDecoder.decode(path.toString(),UTF_8); if (!path.empty()) filename += "/"+URLDecoder.decode(path.toString(),UTF_8);
if (!companies.membership(cid,user.id()) && !fileDb.isPermitted(user,filename)) throw forbidden("You are not allowed to access {0}",filename); if (!companies.membership(cid,user.id()) && !fileDb.isPermitted(user,filename)) throw forbidden("You are not allowed to access {0}",filename);
var file = new File(baseDir+filename); return deleteFile(ex, new File(baseDir+filename));
if (!file.exists()) throw unprocessable("{0} does not exist!",filename);
return false;
} }
private boolean deleteProjectFile(Path path, HttpExchange ex, UmbrellaUser user) throws IOException { private boolean deleteProjectFile(Path path, HttpExchange ex, UmbrellaUser user) throws IOException {
@@ -140,7 +137,7 @@ public class FileModule extends BaseHandler implements FileService {
} }
private boolean deleteUserFile(Path path, HttpExchange ex, UmbrellaUser user) { private boolean deleteUserFile(Path path, HttpExchange ex, UmbrellaUser user) throws IOException {
var userId = path.pop(); var userId = path.pop();
if (userId == null) throw missingFieldException(USER_ID); if (userId == null) throw missingFieldException(USER_ID);
long uid; long uid;
@@ -152,9 +149,7 @@ public class FileModule extends BaseHandler implements FileService {
var filename = "/user/"+uid; var filename = "/user/"+uid;
if (!path.empty()) filename += "/"+URLDecoder.decode(path.toString(),UTF_8); if (!path.empty()) filename += "/"+URLDecoder.decode(path.toString(),UTF_8);
if (uid != user.id() && !fileDb.isPermitted(user,filename)) throw forbidden("You are not allowed to access {0}",filename); if (uid != user.id() && !fileDb.isPermitted(user,filename)) throw forbidden("You are not allowed to access {0}",filename);
var file = new File(baseDir+filename); return deleteFile(ex, new File(baseDir+filename));
if (!file.exists()) throw unprocessable("{0} does not exist!",filename);
return false;
} }
@Override @Override

View File

@@ -75,7 +75,7 @@
let json = await res.json(); let json = await res.json();
children.dirs = json.dirs ? json.dirs : {}; children.dirs = json.dirs ? json.dirs : {};
children.files = json.files ? json.files : {}; children.files = json.files ? json.files : {};
children.title = json.title ? json.title : {}; children.title = json.title ? json.title : path;
delete_allowed = json.delete; delete_allowed = json.delete;
yikes(); yikes();
} }