Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- api/routes_admin.py +28 -0
RELEASES.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v53",
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "a48dacb",
|
| 3 |
"releases": [
|
| 4 |
{
|
| 5 |
"version": "v53",
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
a48dacb
|
api/routes_admin.py
CHANGED
|
@@ -269,6 +269,31 @@ def _tenant_of(rec):
|
|
| 269 |
return str((rec or {}).get("tenant") or "royal-imports").strip().lower()
|
| 270 |
|
| 271 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
# ββ the routes βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 273 |
@router.get("/admin/users")
|
| 274 |
def list_users(session: Session = Depends(admin_gate)):
|
|
@@ -395,6 +420,9 @@ def update_user(username: str, body: dict = Body(default=None),
|
|
| 395 |
"you cannot remove your own administrator role β ask another admin")
|
| 396 |
if is_self and active is False:
|
| 397 |
raise err(400, "self_deactivate", "you cannot deactivate your own account")
|
|
|
|
|
|
|
|
|
|
| 398 |
|
| 399 |
kw = {}
|
| 400 |
if role is not None:
|
|
|
|
| 269 |
return str((rec or {}).get("tenant") or "royal-imports").strip().lower()
|
| 270 |
|
| 271 |
|
| 272 |
+
def _would_leave_tenant_without_admin(reg, username, role=None, active=None):
|
| 273 |
+
"""Whether this one account update would leave its tenant with no active administrator.
|
| 274 |
+
|
| 275 |
+
An administrator is ordinary tenant membership with `role == 'admin'`, not a platform-admin
|
| 276 |
+
flag and not a special schema identity. A tenant without one cannot administer its own users,
|
| 277 |
+
so the invariant belongs at the only user-access writer instead of relying on provisioning
|
| 278 |
+
discipline or the self-lockout guard alone.
|
| 279 |
+
"""
|
| 280 |
+
target = (reg or {}).get(username)
|
| 281 |
+
if not isinstance(target, dict):
|
| 282 |
+
return False
|
| 283 |
+
tenant = _tenant_of(target)
|
| 284 |
+
for uname, record in (reg or {}).items():
|
| 285 |
+
if not isinstance(record, dict) or _tenant_of(record) != tenant:
|
| 286 |
+
continue
|
| 287 |
+
is_target = str(uname).strip().lower() == username
|
| 288 |
+
next_role = (role if is_target and role is not None
|
| 289 |
+
else str(record.get("role") or "user").strip().lower())
|
| 290 |
+
next_active = (active if is_target and active is not None
|
| 291 |
+
else bool(record.get("active", True)))
|
| 292 |
+
if next_role == "admin" and next_active:
|
| 293 |
+
return False
|
| 294 |
+
return True
|
| 295 |
+
|
| 296 |
+
|
| 297 |
# ββ the routes βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 298 |
@router.get("/admin/users")
|
| 299 |
def list_users(session: Session = Depends(admin_gate)):
|
|
|
|
| 420 |
"you cannot remove your own administrator role β ask another admin")
|
| 421 |
if is_self and active is False:
|
| 422 |
raise err(400, "self_deactivate", "you cannot deactivate your own account")
|
| 423 |
+
if _would_leave_tenant_without_admin(reg, uname, role=role, active=active):
|
| 424 |
+
raise err(400, "last_admin",
|
| 425 |
+
"an active tenant must retain at least one administrator")
|
| 426 |
|
| 427 |
kw = {}
|
| 428 |
if role is not None:
|