From c4a6715eb84cb6955e08797e212653af6bf650bf Mon Sep 17 00:00:00 2001 From: feng626 <1304903146@qq.com> Date: Tue, 8 Mar 2022 15:11:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=91=BD=E4=BB=A4=E5=AD=98=E5=82=A8=20o?= =?UTF-8?q?r=20=E5=91=BD=E4=BB=A4=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api/storage.py | 3 +-- apps/users/models/user.py | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/terminal/api/storage.py b/apps/terminal/api/storage.py index e1c635213..f00611bb2 100644 --- a/apps/terminal/api/storage.py +++ b/apps/terminal/api/storage.py @@ -14,7 +14,6 @@ from terminal.filters import CommandStorageFilter, CommandFilter, CommandFilterF from ..models import CommandStorage, ReplayStorage from ..serializers import CommandStorageSerializer, ReplayStorageSerializer - __all__ = [ 'CommandStorageViewSet', 'CommandStorageTestConnectiveApi', 'ReplayStorageViewSet', 'ReplayStorageTestConnectiveApi' @@ -40,7 +39,7 @@ class CommandStorageViewSet(BaseStorageViewSetMixin, viewsets.ModelViewSet): serializer_class = CommandStorageSerializer filterset_class = CommandStorageFilter rbac_perms = { - 'tree': 'terminal.view_commandstorage' + 'tree': 'terminal.view_commandstorage | terminal.view_command' } @action(methods=[GET], detail=False, filterset_class=CommandFilterForStorageTree) diff --git a/apps/users/models/user.py b/apps/users/models/user.py index fec7311b7..04ed568c9 100644 --- a/apps/users/models/user.py +++ b/apps/users/models/user.py @@ -806,6 +806,15 @@ class User(AuthMixin, TokenMixin, RoleMixin, MFAMixin, AbstractUser): return True return False + def has_perms(self, perm_list, obj=None): + """ + Return True if the user has each of the specified permissions. If + object is passed, check if the user has all required perms for it. + """ + if '*' in perm_list: + return True + return all(any(self.has_perm(perm, obj) for perm in perms.split(' | ')) for perms in perm_list) + class UserPasswordHistory(models.Model): id = models.UUIDField(default=uuid.uuid4, primary_key=True)