Browse Source

preparing for deletion of company

module/company
Stephan Richter 3 months ago
parent
commit
f1f9859894
  1. 30
      company/src/main/java/de/srsoftware/umbrella/company/CompanyModule.java
  2. 24
      frontend/src/routes/company/Index.svelte
  3. 2
      translations/src/main/resources/de.json

30
company/src/main/java/de/srsoftware/umbrella/company/CompanyModule.java

@ -32,6 +32,34 @@ public class CompanyModule extends BaseHandler implements CompanyService { @@ -32,6 +32,34 @@ public class CompanyModule extends BaseHandler implements CompanyService {
users = userService;
}
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 = users.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 { @@ -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) {

24
frontend/src/routes/company/Index.svelte

@ -28,6 +28,21 @@ @@ -28,6 +28,21 @@
}
}
async function drop(company){
if (!confirm(t('confirm_delete',{element:company.name}))) return;
const url = api(`company/${company.id}`);
const resp = await fetch(url,{
credentials : 'include',
method : 'DELETE'
});
if (resp.ok){
delete companies[company.id];
error = null;
} else {
error = await resp.text();
}
}
async function loadCompanies(){
const url = api('company/list');
const resp = await fetch(url,{credentials:'include'});
@ -64,7 +79,10 @@ @@ -64,7 +79,10 @@
{t('email')}
</th>
<th>
{t('detail')}
{t('members')}
</th>
<th>
{t('actions')}
</th>
</tr>
</thead>
@ -76,6 +94,7 @@ @@ -76,6 +94,7 @@
<td>
<input type="email" bind:value={new_company.email} />
</td>
<td></td>
<td>
<button disabled={missing_fields} onclick={create_company}>{t('create_new_object',{object:t('company')})}</button>
</td>
@ -91,6 +110,9 @@ @@ -91,6 +110,9 @@
{/each}
</ul>
</td>
<td>
<button onclick={e => drop(company)}>{t('delete_object',{object:t('company')})}</button>
</td>
</tr>
{#if selected==cid}
<tr>

2
translations/src/main/resources/de.json

@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
"data_sent": "Daten übermittelt",
"date": "Datum",
"delete": "löschen",
"delete_task": "Aufgabe löschen ",
"delete_object": "{object} löschen",
"DELETE_USERS": "Nutzer löschen",
"delivery_date": "Lieferdatum",
"description": "Beschreibung",

Loading…
Cancel
Save