fix: 修复 ticket session 监控用户没有权限的问题

pull/9644/head
Bai 2023-02-20 15:08:06 +08:00 committed by Jiangjie.Bai
parent ca6d71f442
commit c456782d9e
3 changed files with 22 additions and 0 deletions

View File

@ -141,3 +141,6 @@ class RBACPermission(permissions.DjangoModelPermissions):
has = request.user.has_perms(perms)
logger.debug('View require perms: {}, result: {}'.format(perms, has))
return has
def has_object_permission(self, request, view, obj):
return self.has_permission(request, view)

View File

@ -22,6 +22,7 @@ from common.drf.renders import PassthroughRenderer
from common.api import AsyncApiMixin
from common.utils import data_to_json, is_uuid
from common.utils import get_logger, get_object_or_none
from rbac.permissions import RBACPermission
from orgs.mixins.api import OrgBulkModelViewSet
from orgs.utils import tmp_to_root_org, tmp_to_org
from terminal import serializers
@ -30,6 +31,7 @@ from terminal.utils import (
find_session_replay_local, download_session_replay,
is_session_approver, get_session_replay_url
)
from terminal.permissions import IsSessionAssignee
from users.models import User
__all__ = [
@ -86,6 +88,7 @@ class SessionViewSet(OrgBulkModelViewSet):
rbac_perms = {
'download': ['terminal.download_sessionreplay']
}
permission_classes = [RBACPermission | IsSessionAssignee]
@staticmethod
def prepare_offline_file(session, local_path):

View File

@ -0,0 +1,16 @@
from rest_framework import permissions
from common.utils import get_logger
logger = get_logger(__file__)
__all__ = ['IsSessionAssignee']
class IsSessionAssignee(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
try:
return obj.ticket_relation.first().ticket.has_all_assignee(request.user)
except:
return False