diff --git a/src/models.py b/src/models.py index 196dc15..763af9f 100644 --- a/src/models.py +++ b/src/models.py @@ -34,6 +34,7 @@ class OrgResponse(BaseModel): license_type: str = "" created_at: str globe_access: bool = False + network_access: bool = False class LicenseCreate(BaseModel): @@ -63,6 +64,7 @@ class LicenseResponse(BaseModel): budget_warning_percent: Optional[int] = None created_at: str globe_access: bool = False + network_access: bool = False class UserCreate(BaseModel): @@ -81,3 +83,4 @@ class UserResponse(BaseModel): last_login_at: Optional[str] created_at: str globe_access: bool = False + network_access: bool = False diff --git a/src/routers/users.py b/src/routers/users.py index 791a322..455e886 100644 --- a/src/routers/users.py +++ b/src/routers/users.py @@ -180,3 +180,20 @@ async def delete_user( await db.execute("DELETE FROM users WHERE id = ?", (user_id,)) await db.commit() + + +@router.put("/{user_id}/network-access") +async def toggle_network_access( + user_id: int, + admin: dict = Depends(get_current_admin), + db: aiosqlite.Connection = Depends(db_dependency), +): + cursor = await db.execute("SELECT id, network_access FROM users WHERE id = ?", (user_id,)) + row = await cursor.fetchone() + if not row: + raise HTTPException(status_code=404, detail="Nutzer nicht gefunden") + + new_val = 0 if row[1] else 1 + await db.execute("UPDATE users SET network_access = ? WHERE id = ?", (new_val, user_id)) + await db.commit() + return {"ok": True, "network_access": bool(new_val)} diff --git a/src/static/dashboard.html b/src/static/dashboard.html index 9a72656..a629e83 100644 --- a/src/static/dashboard.html +++ b/src/static/dashboard.html @@ -108,6 +108,7 @@ Rolle Status Globe + Netzwerk Aktionen diff --git a/src/static/js/app.js b/src/static/js/app.js index 77c3ab9..47fcf0e 100644 --- a/src/static/js/app.js +++ b/src/static/js/app.js @@ -248,6 +248,7 @@ async function loadOrgUsers(orgId) { ${u.is_active ? "Aktiv" : "Inaktiv"} ${u.globe_access ? '' : ''} + ${u.network_access ? '' : ''} ${u.is_active ? `` @@ -290,6 +291,16 @@ async function toggleGlobeAccess(userId) { } } +async function toggleNetworkAccess(userId) { + try { + await API.put("/api/users/" + userId + "/network-access"); + if (currentOrgId) loadOrgUsers(currentOrgId); + } catch (err) { + alert(err.message); + if (currentOrgId) loadOrgUsers(currentOrgId); + } +} + function confirmDeleteUser(userId, email) { showConfirm( "Nutzer löschen",