|
|
|
@ -3,8 +3,7 @@ package de.srsoftware.umbrella.files; |
|
|
|
|
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; |
|
|
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; |
|
|
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.core.ModuleRegistry.projectService; |
|
|
|
import static de.srsoftware.umbrella.core.ModuleRegistry.*; |
|
|
|
import static de.srsoftware.umbrella.core.ModuleRegistry.userService; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*; |
|
|
|
import static de.srsoftware.umbrella.files.Constants.CONFIG_DATABASE; |
|
|
|
import static de.srsoftware.umbrella.files.Constants.CONFIG_DATABASE; |
|
|
|
import static de.srsoftware.umbrella.files.Constants.CONFIG_FILESTORE; |
|
|
|
import static de.srsoftware.umbrella.files.Constants.CONFIG_FILESTORE; |
|
|
|
@ -19,6 +18,7 @@ import de.srsoftware.umbrella.core.BaseHandler; |
|
|
|
import de.srsoftware.umbrella.core.ModuleRegistry; |
|
|
|
import de.srsoftware.umbrella.core.ModuleRegistry; |
|
|
|
import de.srsoftware.umbrella.core.api.FileService; |
|
|
|
import de.srsoftware.umbrella.core.api.FileService; |
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
|
|
|
|
import de.srsoftware.umbrella.core.model.Company; |
|
|
|
import de.srsoftware.umbrella.core.model.Project; |
|
|
|
import de.srsoftware.umbrella.core.model.Project; |
|
|
|
import de.srsoftware.umbrella.core.model.Token; |
|
|
|
import de.srsoftware.umbrella.core.model.Token; |
|
|
|
import de.srsoftware.umbrella.core.model.UmbrellaUser; |
|
|
|
import de.srsoftware.umbrella.core.model.UmbrellaUser; |
|
|
|
@ -71,8 +71,35 @@ public class FileModule extends BaseHandler implements FileService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean getCompanyFiles(Path path, HttpExchange ex, UmbrellaUser user) { |
|
|
|
private boolean getCompanyFiles(Path path, HttpExchange ex, UmbrellaUser user) throws IOException { |
|
|
|
return false; |
|
|
|
var cpId = path.pop(); |
|
|
|
|
|
|
|
var companies = companyService(); |
|
|
|
|
|
|
|
Map<Long, Company> companyList; |
|
|
|
|
|
|
|
if (cpId == null){ |
|
|
|
|
|
|
|
companyList = companies.listCompaniesOf(user); |
|
|
|
|
|
|
|
var map = companyList.values().stream().collect(Collectors.toMap(company -> "/company/"+company.id(), Company::name)); |
|
|
|
|
|
|
|
return sendContent(ex,Map.of("dirs",map)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long cid; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
cid = Long.parseLong(cpId); |
|
|
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
|
|
|
throw invalidFieldException(COMPANY_ID,"Long"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var company = companies.get(cid); |
|
|
|
|
|
|
|
var filename = "/company/"+cid; |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
var file = new File(baseDir+filename); |
|
|
|
|
|
|
|
if (!file.exists()) throw unprocessable("{0} does not exist!",filename); |
|
|
|
|
|
|
|
if (file.isDirectory()){ |
|
|
|
|
|
|
|
Map<String,Object> map = getDirectory(file); |
|
|
|
|
|
|
|
map.put("title",filename.replace("/company/"+cpId,company.name())); |
|
|
|
|
|
|
|
return sendContent(ex,map); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return getFile(ex, file); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean getProjectFiles(Path path, HttpExchange ex, UmbrellaUser user) throws IOException { |
|
|
|
private boolean getProjectFiles(Path path, HttpExchange ex, UmbrellaUser user) throws IOException { |
|
|
|
|