preparing for deletion of company
This commit is contained in:
@@ -32,6 +32,34 @@ public class CompanyModule extends BaseHandler implements CompanyService {
|
|||||||
users = userService;
|
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
|
@Override
|
||||||
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||||
addCors(ex);
|
addCors(ex);
|
||||||
@@ -59,7 +87,7 @@ public class CompanyModule extends BaseHandler implements CompanyService {
|
|||||||
if (user.isEmpty()) return unauthorized(ex);
|
if (user.isEmpty()) return unauthorized(ex);
|
||||||
var head = path.pop();
|
var head = path.pop();
|
||||||
return switch (head) {
|
return switch (head) {
|
||||||
case null -> super.doGet(path, ex);
|
case null -> super.doPatch(path, ex);
|
||||||
default -> patchCompany(Long.parseLong(head), user.get(), ex);
|
default -> patchCompany(Long.parseLong(head), user.get(), ex);
|
||||||
};
|
};
|
||||||
} catch (NumberFormatException n) {
|
} catch (NumberFormatException n) {
|
||||||
|
|||||||
@@ -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(){
|
async function loadCompanies(){
|
||||||
const url = api('company/list');
|
const url = api('company/list');
|
||||||
const resp = await fetch(url,{credentials:'include'});
|
const resp = await fetch(url,{credentials:'include'});
|
||||||
@@ -64,7 +79,10 @@
|
|||||||
{t('email')}
|
{t('email')}
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
{t('detail')}
|
{t('members')}
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
{t('actions')}
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -76,6 +94,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<input type="email" bind:value={new_company.email} />
|
<input type="email" bind:value={new_company.email} />
|
||||||
</td>
|
</td>
|
||||||
|
<td></td>
|
||||||
<td>
|
<td>
|
||||||
<button disabled={missing_fields} onclick={create_company}>{t('create_new_object',{object:t('company')})}</button>
|
<button disabled={missing_fields} onclick={create_company}>{t('create_new_object',{object:t('company')})}</button>
|
||||||
</td>
|
</td>
|
||||||
@@ -91,6 +110,9 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<button onclick={e => drop(company)}>{t('delete_object',{object:t('company')})}</button>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{#if selected==cid}
|
{#if selected==cid}
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
"data_sent": "Daten übermittelt",
|
"data_sent": "Daten übermittelt",
|
||||||
"date": "Datum",
|
"date": "Datum",
|
||||||
"delete": "löschen",
|
"delete": "löschen",
|
||||||
"delete_task": "Aufgabe löschen ",
|
"delete_object": "{object} löschen",
|
||||||
"DELETE_USERS": "Nutzer löschen",
|
"DELETE_USERS": "Nutzer löschen",
|
||||||
"delivery_date": "Lieferdatum",
|
"delivery_date": "Lieferdatum",
|
||||||
"description": "Beschreibung",
|
"description": "Beschreibung",
|
||||||
|
|||||||
Reference in New Issue
Block a user