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()