completed company deletion implementation
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -32,13 +32,13 @@ public class CompanyModule extends BaseHandler implements CompanyService {
|
||||
this.registry = registry.add(this);
|
||||
}
|
||||
|
||||
private boolean deleteCompany(long companyId, UmbrellaUser user, HttpExchange ex) {
|
||||
private boolean deleteCompany(long companyId, UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
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;
|
||||
if (!registry.documentService().list(companyId).isEmpty()) throw forbidden("There are documents owned by {0}",company.name());
|
||||
if (!registry.itemService().list(companyId).isEmpty()) throw forbidden("There are items owned by {0}",company.name());
|
||||
if (!registry.projectService().listCompanyProjects(companyId,true).isEmpty()) throw forbidden("There are projects owned by {0}",company.name());
|
||||
return sendContent(ex, companyDb.drop(companyId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -94,11 +94,22 @@ CREATE TABLE IF NOT EXISTS "companies" (
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropUser(long company_id, long user_id) {
|
||||
public long drop(long companyId) {
|
||||
try {
|
||||
delete().from(TABLE_COMPANIES_USERS).where(COMPANY_ID,equal(company_id)).where(USER_ID,equal(user_id)).execute(db);
|
||||
delete().from(TABLE_COMPANIES_USERS).where(COMPANY_ID,equal(companyId)).execute(db);
|
||||
delete().from(TABLE_COMPANIES).where(ID,equal(companyId)).execute(db);
|
||||
return companyId;
|
||||
} catch (SQLException e) {
|
||||
throw databaseException("Failed to assign user {0} to company {1}");
|
||||
throw databaseException("Failed to remove company {0}",companyId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropUser(long companyId, long userId) {
|
||||
try {
|
||||
delete().from(TABLE_COMPANIES_USERS).where(COMPANY_ID,equal(companyId)).where(USER_ID,equal(userId)).execute(db);
|
||||
} catch (SQLException e) {
|
||||
throw databaseException("Failed to remove user {0} from company {1}",userId,companyId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,15 @@ import java.util.Map;
|
||||
public interface CompanyDb {
|
||||
void addUser(long company_id, long user_id);
|
||||
|
||||
long drop(long companyId);
|
||||
|
||||
void dropUser(long company_id, long user_id);
|
||||
|
||||
Collection<Long> getMembers(long companyId) throws UmbrellaException;
|
||||
|
||||
Map<Long,Company> listCompaniesOf(long id) throws UmbrellaException;
|
||||
|
||||
|
||||
Company load(long companyId) throws UmbrellaException;
|
||||
|
||||
Company save(Company company);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user