Merge branch 'main' into dev

This commit is contained in:
2025-11-24 16:54:43 +01:00

View File

@@ -229,11 +229,14 @@ public class FileModule extends BaseHandler implements FileService {
} }
var company = companies.get(cid); var company = companies.get(cid);
var filename = "/company/"+cid; var companyDir = "/company/"+cid;
if (!path.empty()) filename += "/"+URLDecoder.decode(path.toString(),UTF_8); var filename = path.empty() ? companyDir : companyDir + "/"+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); var file = new File(baseDir+filename);
if (!file.exists()) throw unprocessable("{0} does not exist!",filename); if (!file.exists()){
if (!filename.equals(companyDir)) throw unprocessable("{0} does not exist!",filename);
if (!file.mkdirs()) throw unprocessable("Failed to create directory {0}!",filename);
}
if (file.isDirectory()){ if (file.isDirectory()){
Map<String,Object> map = getDirectory(file); Map<String,Object> map = getDirectory(file);
map.put("title",filename.replace("/company/"+cpId,company.name())); map.put("title",filename.replace("/company/"+cpId,company.name()));
@@ -286,11 +289,14 @@ public class FileModule extends BaseHandler implements FileService {
throw invalidFieldException(PROJECT_ID,"Long"); throw invalidFieldException(PROJECT_ID,"Long");
} }
var project = projects.loadMembers(projects.load(pid)); var project = projects.loadMembers(projects.load(pid));
var filename = "/project/"+pid; var projectDir = "/project/"+pid;
if (!path.empty()) filename += "/"+URLDecoder.decode(path.toString(),UTF_8); var filename = path.empty() ? projectDir : projectDir+"/"+URLDecoder.decode(path.toString(),UTF_8);
if (!project.hasMember(user) && !fileDb.isPermitted(user,filename)) throw forbidden("You are not allowed to access {0}",filename); if (!project.hasMember(user) && !fileDb.isPermitted(user,filename)) throw forbidden("You are not allowed to access {0}",filename);
var file = new File(baseDir+filename); var file = new File(baseDir+filename);
if (!file.exists()) throw unprocessable("{0} does not exist!",filename); if (!file.exists()){
if (!filename.equals(projectDir)) throw unprocessable("{0} does not exist!",filename);
if (!file.mkdirs()) throw unprocessable("Failed to create directory {0}!",filename);
}
if (file.isDirectory()){ if (file.isDirectory()){
Map<String,Object> map = getDirectory(file); Map<String,Object> map = getDirectory(file);
map.put("title",filename.replace("/project/"+prjId,project.name())); map.put("title",filename.replace("/project/"+prjId,project.name()));
@@ -309,12 +315,15 @@ public class FileModule extends BaseHandler implements FileService {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw invalidFieldException(PROJECT_ID,"Long"); throw invalidFieldException(PROJECT_ID,"Long");
} }
var filename = "/user/"+uid; var userDir = "/user/"+uid;
var filename = path.empty() ? userDir : userDir+"/"+URLDecoder.decode(path.toString(),UTF_8);
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); var file = new File(baseDir+filename);
if (!file.exists()) throw unprocessable("{0} does not exist!",filename); if (!file.exists()){
if (file.isDirectory()){ if (!filename.equals(userDir)) throw unprocessable("{0} does not exist!",filename);
if (!file.mkdirs()) throw unprocessable("Failed to create directory {0}!",filename);
} if (file.isDirectory()){
Map<String,Object> map = getDirectory(file); Map<String,Object> map = getDirectory(file);
map.put("title",filename); map.put("title",filename);
map.put("delete",true); map.put("delete",true);