From 1076c95f78140a5a43b0ba59ff1072fb60561eed Mon Sep 17 00:00:00 2001 From: benero Date: Tue, 24 Sep 2024 10:47:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=9D=83=E9=99=90=E5=BC=82=E5=B8=B8=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20--story=3D119807844?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- itsm/component/drf/permissions.py | 7 +++++++ itsm/project/views.py | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/itsm/component/drf/permissions.py b/itsm/component/drf/permissions.py index 1ba82441..64b36137 100644 --- a/itsm/component/drf/permissions.py +++ b/itsm/component/drf/permissions.py @@ -116,6 +116,13 @@ def has_object_permission(self, request, view, obj, **kwargs): if hasattr(view, "permission_action_mapping"): apply_actions = view.permission_action_mapping.get(view.action) + # 默认动作 + if not apply_actions and hasattr(view, "permission_action_default"): + apply_actions = view.permission_action_default + + if isinstance(apply_actions, str): + apply_actions = [apply_actions] + return self.iam_auth(request, apply_actions, obj) def iam_auth(self, request, apply_actions, obj=None): diff --git a/itsm/project/views.py b/itsm/project/views.py index 460db2e9..dc77aec2 100644 --- a/itsm/project/views.py +++ b/itsm/project/views.py @@ -62,8 +62,10 @@ class ProjectViewSet(component_viewsets.AuthModelViewSet): "name": ["exact", "contains", "startswith", "icontains"], } + permission_action_default = ["project_edit"] permission_action_mapping = { - "retrieve": ["project_view"] + "retrieve": ["project_view"], + "update_project_record": ["project_view"] } def list(self, request, *args, **kwargs):