From 9cfd5504858a239103d0331ef198d2e6b7e19207 Mon Sep 17 00:00:00 2001 From: seaislee1209 Date: Sat, 28 Mar 2026 21:59:39 +0800 Subject: [PATCH] fix: sync separates account status from console login status - Account status now comes from Volcengine User.Status field (active/disabled) - Console login status synced to volc_login_allowed separately - Fixes: closing Volcengine login no longer marks account as disabled after sync - Handles ghost LoginProfile (CreateDate=1970) correctly during sync Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/apps/monitor/views.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/backend/apps/monitor/views.py b/backend/apps/monitor/views.py index 34db3f3..2a16e17 100644 --- a/backend/apps/monitor/views.py +++ b/backend/apps/monitor/views.py @@ -213,13 +213,26 @@ def iam_user_sync_view(request): except Exception: pass - # Sync login status + # Sync account status from Volcengine user status (not login profile) + volc_status = u.get("Status", "active") + if volc_status == "active": + obj.status = IAMUser.Status.ACTIVE + elif volc_status == "disabled": + obj.status = IAMUser.Status.DISABLED + else: + obj.status = IAMUser.Status.UNKNOWN + + # Sync volc login status separately try: profile = svc.get_login_profile(username) - login_allowed = profile.get("Result", {}).get("LoginProfile", {}).get("LoginAllowed", True) - obj.status = IAMUser.Status.ACTIVE if login_allowed else IAMUser.Status.DISABLED + lp = profile.get("Result", {}).get("LoginProfile", {}) + create_date = lp.get("CreateDate", "") + if create_date.startswith("1970") or create_date.startswith("0001"): + obj.volc_login_allowed = False + else: + obj.volc_login_allowed = lp.get("LoginAllowed", False) except Exception: - obj.status = IAMUser.Status.UNKNOWN + obj.volc_login_allowed = False obj.save()