1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-17 07:41:26 +00:00
This commit is contained in:
孙永强
2024-11-22 14:17:30 +08:00
parent 631320c889
commit b1c44da366
4 changed files with 23 additions and 32 deletions

View File

@@ -158,10 +158,7 @@ class Notification extends React.Component {
</NotificationPopover>
}
{this.state.isShowNotificationDialog &&
<UserNotificationsDialog
onNotificationDialogToggle={this.onNotificationDialogToggle}
tabItemClick={this.tabItemClick}
/>
<UserNotificationsDialog onNotificationDialogToggle={this.onNotificationDialogToggle} />
}
</div>
);

View File

@@ -1,16 +1,6 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import {
Modal,
ModalHeader,
ModalBody,
Dropdown,
DropdownToggle,
DropdownMenu,
DropdownItem,
TabPane,
Nav, NavItem, NavLink, TabContent
} from 'reactstrap';
import { Modal, ModalHeader, ModalBody, Dropdown, DropdownToggle, DropdownMenu, DropdownItem, TabPane, Nav, NavItem, NavLink, TabContent } from 'reactstrap';
import { Utils } from './utils/utils';
import { gettext } from './utils/constants';
import { seafileAPI } from './utils/seafile-api';
@@ -311,8 +301,7 @@ class UserNotificationsDialog extends React.Component {
}
UserNotificationsDialog.propTypes = {
onNotificationDialogToggle: PropTypes.func.isRequired,
tabItemClick: PropTypes.func.isRequired,
onNotificationDialogToggle: PropTypes.func.isRequired
};
export default UserNotificationsDialog;

View File

@@ -168,6 +168,11 @@ class NotificationView(APIView):
class SdocNotificationsView(APIView):
authentication_classes = (TokenAuthentication, SessionAuthentication)
permission_classes = (IsAuthenticated,)
throttle_classes = (UserRateThrottle,)
def get(self, request):
""" used for get sdoc notifications
@@ -175,7 +180,6 @@ class SdocNotificationsView(APIView):
1. login user.
"""
result = {}
username = request.user.username
try:
@@ -185,10 +189,14 @@ class SdocNotificationsView(APIView):
per_page = 25
page = 1
if page < 1:
error_msg = 'page invalid'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
start = (page - 1) * per_page
end = page * per_page
notice_list = SeadocNotification.objects.list_all_by_user(username, start, end)
notice_list = SeadocNotification.objects.list_all_by_user(username)[start:end]
result_notices = update_sdoc_notice_detail(request, notice_list)
notification_list = []
for i in result_notices:
@@ -220,12 +228,6 @@ class SdocNotificationsView(APIView):
return Response(result)
def put(self, request):
""" currently only used for mark all notifications seen
Permission checking:
1. login user.
"""
username = request.user.username
unseen_notices = SeadocNotification.objects.filter(username=username, seen=False)
for notice in unseen_notices:
@@ -328,19 +330,22 @@ class AllNotificationsView(APIView):
per_page = 25
page = 1
if page < 1:
error_msg = 'page invalid'
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
start = (page - 1) * per_page
end = page * per_page
notice_list = UserNotification.objects.get_user_notifications(username)[start:end]
sdoc_notice_list = SeadocNotification.objects.list_all_by_user(username, start, end)
general_notice_list = UserNotification.objects.get_user_notifications(username)[start:end]
sdoc_notice_list = SeadocNotification.objects.list_all_by_user(username)[start:end]
result_notices = update_notice_detail(request, notice_list)
general_result_notices = update_notice_detail(request, general_notice_list)
sdoc_result_notices = update_sdoc_notice_detail(request, sdoc_notice_list)
notification_list = []
sdoc_notification_list = []
for i in result_notices:
for i in general_result_notices:
if i.detail is not None:
notice = {}
notice['id'] = i.id

View File

@@ -270,8 +270,8 @@ class SeadocNotificationManager(models.Manager):
def delete_by_ids(self, doc_uuid, username, ids):
return self.filter(doc_uuid=doc_uuid, username=username, id__in=ids).delete()
def list_all_by_user(self, username, start, end):
return self.filter(username=username).order_by('-created_at')[start: end]
def list_all_by_user(self, username):
return self.filter(username=username).order_by('-created_at')
def remove_user_notifications(self, username):
""""Remove all user notifications."""