Merge branch 'module/company' into dev

This commit is contained in:
2025-08-09 13:51:03 +02:00
3 changed files with 53 additions and 3 deletions

View File

@@ -32,6 +32,34 @@ public class CompanyModule extends BaseHandler implements CompanyService {
this.registry = registry.add(this);
}
private boolean deleteCompany(long companyId, UmbrellaUser user, HttpExchange ex) {
var company = get(companyId);
if (!membership(companyId,user.id())) throw forbidden("You are mot a member of company {0}",company.name());
// TODO: check, whether company is referenced by a document
// TODO: check, whether company is referenced by a item
// TODO: check, whether company is referenced by a project
return false;
}
@Override
public boolean doDelete(Path path, HttpExchange ex) throws IOException {
addCors(ex);
try {
Optional<Token> token = SessionToken.from(ex).map(Token::of);
var user = registry.userService().loadUser(token);
if (user.isEmpty()) return unauthorized(ex);
var head = path.pop();
return switch (head) {
case null -> super.doDelete(path, ex);
default -> deleteCompany(Long.parseLong(head), user.get(), ex);
};
} catch (NumberFormatException n) {
return send(ex,invalidFieldException(ID,"ID (Long)"));
} catch (UmbrellaException e) {
return send(ex,e);
}
}
@Override
public boolean doGet(Path path, HttpExchange ex) throws IOException {
addCors(ex);
@@ -59,7 +87,7 @@ public class CompanyModule extends BaseHandler implements CompanyService {
if (user.isEmpty()) return unauthorized(ex);
var head = path.pop();
return switch (head) {
case null -> super.doGet(path, ex);
case null -> super.doPatch(path, ex);
default -> patchCompany(Long.parseLong(head), user.get(), ex);
};
} catch (NumberFormatException n) {