fix: 命令存储 or 命令权限

pull/7772/head
feng626 2022-03-08 15:11:26 +08:00 committed by Jiangjie.Bai
parent 4c31b5ec0f
commit c4a6715eb8
2 changed files with 10 additions and 2 deletions

View File

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

View File

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