mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-08 02:39:22 +00:00
fix: 站内信未读信息计数不准
This commit is contained in:
@@ -2,6 +2,7 @@ from rest_framework.response import Response
|
||||
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
|
||||
from rest_framework.decorators import action
|
||||
|
||||
from common.http import is_true
|
||||
from common.permissions import IsValidUser
|
||||
from common.const.http import GET, PATCH, POST
|
||||
from common.drf.api import JmsGenericViewSet
|
||||
@@ -26,13 +27,18 @@ class SiteMessageViewSet(ListModelMixin, RetrieveModelMixin, JmsGenericViewSet):
|
||||
|
||||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
msgs = SiteMessage.get_user_all_msgs(user.id)
|
||||
has_read = self.request.query_params.get('has_read')
|
||||
|
||||
if has_read is None:
|
||||
msgs = SiteMessage.get_user_all_msgs(user.id)
|
||||
else:
|
||||
msgs = SiteMessage.filter_user_msgs(user.id, has_read=is_true(has_read))
|
||||
return msgs
|
||||
|
||||
@action(methods=[GET], detail=False, url_path='unread-total')
|
||||
def unread_total(self, request, **kwargs):
|
||||
user = request.user
|
||||
msgs = SiteMessage.get_user_unread_msgs(user.id)
|
||||
msgs = SiteMessage.filter_user_msgs(user.id, has_read=False)
|
||||
return Response(data={'total': msgs.count()})
|
||||
|
||||
@action(methods=[PATCH], detail=False, url_path='mark-as-read')
|
||||
|
Reference in New Issue
Block a user