feat: Gruppen-Mitgliedschaft direkt aus der Kundenportal-Geräteliste verwalten
Gegenstück zur bestehenden Verwaltung von der Gruppen-Seite aus
(/gruppen/{id}) - jetzt auch umgekehrt vom Gerät aus möglich, ohne
anode-Änderung (fetch_gruppen() aus routers/gruppen.py wiederverwendet,
Diff-Berechnung gegen bestehende add/remove-Endpunkte).
geraete_liste(): neue Spalte 'Gruppen' (aktuelle Mitgliedschaft),
Aktionen-Dropdown bekommt eine Checkbox-Liste aller Organisations-
Gruppen; POST /geraete/{id}/gruppen berechnet die Differenz zur
gewünschten Auswahl und ruft die bestehenden Endpunkte entsprechend auf.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
ca25ce030e
commit
24ac11137d
@ -3,6 +3,7 @@ from fastapi.responses import RedirectResponse
|
|||||||
|
|
||||||
from anode_client import anode_request
|
from anode_client import anode_request
|
||||||
from auth import get_current_user
|
from auth import get_current_user
|
||||||
|
from routers.gruppen import fetch_gruppen
|
||||||
from templating import templates
|
from templating import templates
|
||||||
|
|
||||||
|
|
||||||
@ -83,13 +84,64 @@ def geraete_liste(request: Request, user: dict = Depends(get_current_user)):
|
|||||||
oe_result = anode_request("GET", f"/api/v1/organizations/{user.organization_id}/organisationseinheiten")
|
oe_result = anode_request("GET", f"/api/v1/organizations/{user.organization_id}/organisationseinheiten")
|
||||||
organisationseinheiten = oe_result.get("organisationseinheiten", []) if oe_result.get("success") else []
|
organisationseinheiten = oe_result.get("organisationseinheiten", []) if oe_result.get("success") else []
|
||||||
|
|
||||||
|
gruppen = fetch_gruppen(user.organization_id)
|
||||||
|
|
||||||
|
# anode bietet keinen direkten "Gruppen eines Geräts, für alle Geräte
|
||||||
|
# auf einmal"-Endpunkt an - daher hier je Gerät einzeln abfragen
|
||||||
|
# (gleiches N+1-Muster wie admin_kunden.py:gruppe_detail(), nur in
|
||||||
|
# umgekehrter Richtung: dort Geräte einer Gruppe, hier Gruppen eines
|
||||||
|
# Geräts). Bei der aktuellen Kundenzahl/Gerätezahl unproblematisch.
|
||||||
|
for device in devices:
|
||||||
|
dg_result = anode_request("GET", f"/api/v1/devices/{device['id']}/gruppen")
|
||||||
|
device_gruppen = dg_result.get("gruppen", []) if dg_result.get("success") else []
|
||||||
|
device["gruppen_ids"] = {g["id"] for g in device_gruppen}
|
||||||
|
device["gruppen_namen"] = [g["name"] for g in device_gruppen]
|
||||||
|
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
request,
|
request,
|
||||||
"geraete_liste.html",
|
"geraete_liste.html",
|
||||||
{"user": user, "devices": devices, "organisationseinheiten": organisationseinheiten},
|
{
|
||||||
|
"user": user,
|
||||||
|
"devices": devices,
|
||||||
|
"organisationseinheiten": organisationseinheiten,
|
||||||
|
"gruppen": gruppen,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/geraete/{device_id}/gruppen")
|
||||||
|
async def gruppen_aktualisieren(request: Request, device_id: str, user: dict = Depends(get_current_user)):
|
||||||
|
"""
|
||||||
|
Setzt die Gruppen-Mitgliedschaft eines Geräts direkt aus der
|
||||||
|
Geräteliste heraus (Checkbox-Auswahl aller Gruppen der Organisation),
|
||||||
|
als Gegenstück zur bestehenden Verwaltung von der Gruppen-Seite aus
|
||||||
|
(/gruppen/{id}, siehe ADR-0012-Nachtrag). Berechnet die Differenz
|
||||||
|
zwischen aktueller und gewünschter Mitgliedschaft und ruft die
|
||||||
|
bestehenden anode-Endpunkte entsprechend auf - kein neuer
|
||||||
|
Bulk-Endpunkt nötig.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if find_device_in_organization(device_id, user.organization_id) is None:
|
||||||
|
raise HTTPException(status_code=404, detail="Gerät wurde nicht gefunden.")
|
||||||
|
|
||||||
|
form = await request.form()
|
||||||
|
ausgewaehlt = set(form.getlist("gruppen_ids"))
|
||||||
|
|
||||||
|
aktuell_result = anode_request("GET", f"/api/v1/devices/{device_id}/gruppen")
|
||||||
|
aktuell = (
|
||||||
|
{g["id"] for g in aktuell_result.get("gruppen", [])}
|
||||||
|
if aktuell_result.get("success") else set()
|
||||||
|
)
|
||||||
|
|
||||||
|
for gruppe_id in ausgewaehlt - aktuell:
|
||||||
|
anode_request("POST", f"/api/v1/devices/{device_id}/gruppen/{gruppe_id}")
|
||||||
|
|
||||||
|
for gruppe_id in aktuell - ausgewaehlt:
|
||||||
|
anode_request("DELETE", f"/api/v1/devices/{device_id}/gruppen/{gruppe_id}")
|
||||||
|
|
||||||
|
return RedirectResponse("/geraete", status_code=303)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/geraete/{device_id}")
|
@router.get("/geraete/{device_id}")
|
||||||
def auftragskatalog_ansicht(request: Request, device_id: str, user: dict = Depends(get_current_user)):
|
def auftragskatalog_ansicht(request: Request, device_id: str, user: dict = Depends(get_current_user)):
|
||||||
device = find_device_in_organization(device_id, user.organization_id)
|
device = find_device_in_organization(device_id, user.organization_id)
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
<figure>
|
<figure>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr><th>Hostname</th><th>Kennung</th><th>OE</th><th>Letzter Check-in</th><th>Status</th><th></th><th></th></tr>
|
<tr><th>Hostname</th><th>Kennung</th><th>OE</th><th>Gruppen</th><th>Letzter Check-in</th><th>Status</th><th></th><th></th></tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for device in devices %}
|
{% for device in devices %}
|
||||||
@ -16,6 +16,7 @@
|
|||||||
<td>{{ device.hostname or "—" }}</td>
|
<td>{{ device.hostname or "—" }}</td>
|
||||||
<td><code>{{ device.device_fingerprint }}</code></td>
|
<td><code>{{ device.device_fingerprint }}</code></td>
|
||||||
<td>{{ device.oe_name or "—" }}</td>
|
<td>{{ device.oe_name or "—" }}</td>
|
||||||
|
<td>{{ device.gruppen_namen | join(", ") if device.gruppen_namen else "—" }}</td>
|
||||||
<td>{{ device.agent_last_checkin or "noch nie" }}</td>
|
<td>{{ device.agent_last_checkin or "noch nie" }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% if device.deprovisioned_at %}
|
{% if device.deprovisioned_at %}
|
||||||
@ -52,6 +53,24 @@
|
|||||||
<button type="submit" class="outline">In OE verschieben</button>
|
<button type="submit" class="outline">In OE verschieben</button>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
{% if gruppen %}
|
||||||
|
<form method="post" action="/geraete/{{ device.id }}/gruppen">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Gruppen</legend>
|
||||||
|
{% for gruppe in gruppen %}
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="gruppen_ids" value="{{ gruppe.id }}" {% if gruppe.id in device.gruppen_ids %}checked{% endif %}>
|
||||||
|
{{ gruppe.name }}
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
</fieldset>
|
||||||
|
<button type="submit" class="outline">Gruppen aktualisieren</button>
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<small>Keine Gruppen vorhanden. <a href="/gruppen">Gruppe anlegen</a></small>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
<li><a href="/geraete/{{ device.id }}/loeschen">Gerät löschen</a></li>
|
<li><a href="/geraete/{{ device.id }}/loeschen">Gerät löschen</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user