1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-04-28 03:10:45 +00:00
This commit is contained in:
孙永强 2024-11-26 10:56:09 +08:00
parent b1c44da366
commit f4558a0f46
4 changed files with 40 additions and 28 deletions

View File

@ -17,7 +17,7 @@ from seahub.seadoc.models import get_cache_key_of_unseen_sdoc_notifications
from seahub.notifications.models import get_cache_key_of_unseen_notifications
from seahub.notifications.utils import update_notice_detail, update_sdoc_notice_detail
from seahub.api2.utils import api_error
from seahub.seadoc.models import SeadocCommentReply, SeadocNotification
from seahub.seadoc.models import SeadocNotification
from seahub.utils.timeutils import datetime_to_isoformat_timestr
logger = logging.getLogger(__name__)
@ -228,12 +228,15 @@ class SdocNotificationsView(APIView):
return Response(result)
def put(self, request):
"""mark all sdoc notifications seen"""
username = request.user.username
unseen_notices = SeadocNotification.objects.filter(username=username, seen=False)
for notice in unseen_notices:
notice.seen = True
notice.save()
try:
SeadocNotification.objects.filter(username=username, seen=False).update(seen=True)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
cache_key = get_cache_key_of_unseen_sdoc_notifications(username)
cache.delete(cache_key)
@ -327,7 +330,7 @@ class AllNotificationsView(APIView):
per_page = int(request.GET.get('per_page', ''))
page = int(request.GET.get('page', ''))
except ValueError:
per_page = 25
per_page = 5
page = 1
if page < 1:

View File

@ -405,30 +405,37 @@ def update_notice_detail(request, notices):
def update_sdoc_notice_detail(request, notices):
doc_uuid_set = set()
for notice in notices:
doc_uuid_set.add(notice.doc_uuid)
doc_uuid_map = {}
uuids = FileUUIDMap.objects.get_fileuuidmap_in_uuids(doc_uuid_set)
for uuid in uuids:
if uuid not in doc_uuid_map:
origin_file_path = posixpath.join(uuid.parent_path, uuid.filename)
doc_uuid_map[str(uuid.uuid)] = (origin_file_path, uuid.filename, uuid.repo_id)
for notice in notices:
uuid = doc_uuid_map[notice.doc_uuid]
if notice.is_comment():
try:
d = json.loads(notice.detail)
uuid = FileUUIDMap.objects.get_fileuuidmap_by_uuid(notice.doc_uuid)
origin_file_path = posixpath.join(uuid.parent_path, uuid.filename)
url, _, _ = api_avatar_url(d['author'])
d['avatar_url'] = url
d['sdoc_path'] = origin_file_path
d['sdoc_name'] = uuid.filename
d['repo_id'] = uuid.repo_id
d['sdoc_path'] = uuid[0]
d['sdoc_name'] = uuid[1]
d['repo_id'] = uuid[2]
notice.detail = d
except Exception as e:
logger.error(e)
elif notice.is_reply():
try:
d = json.loads(notice.detail)
uuid = FileUUIDMap.objects.get_fileuuidmap_by_uuid(notice.doc_uuid)
origin_file_path = posixpath.join(uuid.parent_path, uuid.filename)
url, _, _ = api_avatar_url(d['author'])
d['avatar_url'] = url
d['sdoc_path'] = origin_file_path
d['sdoc_name'] = uuid.filename
d['repo_id'] = uuid.repo_id
d['sdoc_path'] = uuid[0]
d['sdoc_name'] = uuid[1]
d['repo_id'] = uuid[2]
notice.detail = d
except Exception as e:
logger.error(e)

View File

@ -29,6 +29,7 @@ from django.core.files.uploadhandler import TemporaryFileUploadHandler
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from django.views.decorators.http import condition
from django.core.cache import cache
from seaserv import seafile_api, check_quota, get_org_id_by_repo_id, ccnet_api
@ -54,7 +55,7 @@ from seahub.utils import get_file_type_and_ext, normalize_file_path, \
from seahub.tags.models import FileUUIDMap
from seahub.utils.error_msg import file_type_error_msg
from seahub.utils.repo import parse_repo_perm, get_related_users_by_repo
from seahub.seadoc.models import SeadocHistoryName, SeadocRevision, SeadocCommentReply, SeadocNotification
from seahub.seadoc.models import SeadocHistoryName, SeadocRevision, SeadocCommentReply, SeadocNotification, get_cache_key_of_unseen_sdoc_notifications
from seahub.avatar.templatetags.avatar_tags import api_avatar_url
from seahub.base.templatetags.seahub_tags import email2nickname, \
email2contact_email
@ -1102,11 +1103,6 @@ class SeadocCommentsView(APIView):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
try:
avatar_size = int(request.GET.get('avatar_size', AVATAR_DEFAULT_SIZE))
except ValueError:
avatar_size = AVATAR_DEFAULT_SIZE
comment = request.data.get('comment', '')
detail = request.data.get('detail', '')
author = request.data.get('author', '')
@ -1149,6 +1145,9 @@ class SeadocCommentsView(APIView):
))
try:
SeadocNotification.objects.bulk_create(new_notifications)
# delete sdoc notification count cache
sdoc_cache_key = get_cache_key_of_unseen_sdoc_notifications(username)
cache.delete(sdoc_cache_key)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
@ -1172,11 +1171,6 @@ class SeadocCommentView(APIView):
error_msg = 'Permission denied.'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
try:
avatar_size = int(request.GET.get('avatar_size', AVATAR_DEFAULT_SIZE))
except ValueError:
avatar_size = AVATAR_DEFAULT_SIZE
# resource check
try:
file_comment = FileComment.objects.get(pk=comment_id)
@ -1378,6 +1372,8 @@ class SeadocCommentRepliesView(APIView):
))
try:
SeadocNotification.objects.bulk_create(new_notifications)
sdoc_cache_key = get_cache_key_of_unseen_sdoc_notifications(username)
cache.delete(sdoc_cache_key)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'

View File

@ -21,6 +21,12 @@ class FileUUIDMapManager(models.Manager):
return super(FileUUIDMapManager, self).get(uuid=uuid)
except self.model.DoesNotExist:
return None
def get_fileuuidmap_in_uuids(self, uuids):
try:
return super(FileUUIDMapManager, self).filter(uuid__in=uuids)
except self.model.DoesNotExist:
return None
def get_or_create_fileuuidmap(self, repo_id, parent_path, filename, is_dir):
""" create filemap by repo_id、 parent_path、filename、id_dir