From 6dd3ac5c0d57950d55c0a617aa672ca8752313d7 Mon Sep 17 00:00:00 2001 From: seaislee1209 Date: Fri, 20 Mar 2026 19:20:00 +0800 Subject: [PATCH] fix: handle PolicyAttachConflict when adding project policies Global policies conflict with project-level attach - treat as success since the user already has the permission globally. Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/apps/monitor/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/apps/monitor/views.py b/backend/apps/monitor/views.py index 31f1199..c0bbf24 100644 --- a/backend/apps/monitor/views.py +++ b/backend/apps/monitor/views.py @@ -610,7 +610,11 @@ def iam_user_project_add_view(request, pk): d['project_name']) attached.append(policy_name) except VolcengineAPIError as e: - auth_errors.append(f"{policy_name}: {e}") + if 'PolicyAttachConflict' in str(e): + # 全局已有此策略,项目级无需重复附加,视为成功 + attached.append(policy_name) + else: + auth_errors.append(f"{policy_name}: {e}") obj.attached_policies = attached obj.save(update_fields=['attached_policies'])