Update app.py
This commit is contained in:
16
app.py
16
app.py
@@ -62,9 +62,20 @@ def sync_unifi_users():
|
||||
users = r.json().get("data", [])
|
||||
with get_db() as db:
|
||||
for u in users:
|
||||
# Prefer the same ID used in webhooks (identity ID)
|
||||
actor_id = (
|
||||
u.get("id") or
|
||||
u.get("identity_id") or
|
||||
u.get("user_id")
|
||||
)
|
||||
|
||||
if not actor_id:
|
||||
continue # skip malformed entries
|
||||
|
||||
full_name = (u.get("full_name") or "").strip()
|
||||
if not full_name:
|
||||
full_name = f"{u.get('first_name','')} {u.get('last_name','')}".strip()
|
||||
|
||||
db.execute(
|
||||
"""
|
||||
INSERT INTO user_cache (actor_id, full_name, updated_at)
|
||||
@@ -74,11 +85,12 @@ def sync_unifi_users():
|
||||
updated_at = excluded.updated_at
|
||||
""",
|
||||
(
|
||||
u["id"],
|
||||
full_name or f"User {u['id'][:8]}",
|
||||
actor_id,
|
||||
full_name or f"User {actor_id[:8]}",
|
||||
datetime.utcnow().isoformat(),
|
||||
),
|
||||
)
|
||||
|
||||
db.commit()
|
||||
log.info("Synced %d users from UniFi Access", len(users))
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user