mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-17 15:53:28 +00:00
optimize
This commit is contained in:
@@ -158,10 +158,7 @@ class Notification extends React.Component {
|
|||||||
</NotificationPopover>
|
</NotificationPopover>
|
||||||
}
|
}
|
||||||
{this.state.isShowNotificationDialog &&
|
{this.state.isShowNotificationDialog &&
|
||||||
<UserNotificationsDialog
|
<UserNotificationsDialog onNotificationDialogToggle={this.onNotificationDialogToggle} />
|
||||||
onNotificationDialogToggle={this.onNotificationDialogToggle}
|
|
||||||
tabItemClick={this.tabItemClick}
|
|
||||||
/>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@@ -1,16 +1,6 @@
|
|||||||
import React, { Fragment } from 'react';
|
import React, { Fragment } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import {
|
import { Modal, ModalHeader, ModalBody, Dropdown, DropdownToggle, DropdownMenu, DropdownItem, TabPane, Nav, NavItem, NavLink, TabContent } from 'reactstrap';
|
||||||
Modal,
|
|
||||||
ModalHeader,
|
|
||||||
ModalBody,
|
|
||||||
Dropdown,
|
|
||||||
DropdownToggle,
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownItem,
|
|
||||||
TabPane,
|
|
||||||
Nav, NavItem, NavLink, TabContent
|
|
||||||
} from 'reactstrap';
|
|
||||||
import { Utils } from './utils/utils';
|
import { Utils } from './utils/utils';
|
||||||
import { gettext } from './utils/constants';
|
import { gettext } from './utils/constants';
|
||||||
import { seafileAPI } from './utils/seafile-api';
|
import { seafileAPI } from './utils/seafile-api';
|
||||||
@@ -311,8 +301,7 @@ class UserNotificationsDialog extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserNotificationsDialog.propTypes = {
|
UserNotificationsDialog.propTypes = {
|
||||||
onNotificationDialogToggle: PropTypes.func.isRequired,
|
onNotificationDialogToggle: PropTypes.func.isRequired
|
||||||
tabItemClick: PropTypes.func.isRequired,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default UserNotificationsDialog;
|
export default UserNotificationsDialog;
|
||||||
|
@@ -168,6 +168,11 @@ class NotificationView(APIView):
|
|||||||
|
|
||||||
|
|
||||||
class SdocNotificationsView(APIView):
|
class SdocNotificationsView(APIView):
|
||||||
|
|
||||||
|
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||||
|
permission_classes = (IsAuthenticated,)
|
||||||
|
throttle_classes = (UserRateThrottle,)
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
""" used for get sdoc notifications
|
""" used for get sdoc notifications
|
||||||
|
|
||||||
@@ -175,7 +180,6 @@ class SdocNotificationsView(APIView):
|
|||||||
1. login user.
|
1. login user.
|
||||||
"""
|
"""
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
username = request.user.username
|
username = request.user.username
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -185,10 +189,14 @@ class SdocNotificationsView(APIView):
|
|||||||
per_page = 25
|
per_page = 25
|
||||||
page = 1
|
page = 1
|
||||||
|
|
||||||
|
if page < 1:
|
||||||
|
error_msg = 'page invalid'
|
||||||
|
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||||
|
|
||||||
start = (page - 1) * per_page
|
start = (page - 1) * per_page
|
||||||
end = page * 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)
|
result_notices = update_sdoc_notice_detail(request, notice_list)
|
||||||
notification_list = []
|
notification_list = []
|
||||||
for i in result_notices:
|
for i in result_notices:
|
||||||
@@ -220,12 +228,6 @@ class SdocNotificationsView(APIView):
|
|||||||
return Response(result)
|
return Response(result)
|
||||||
|
|
||||||
def put(self, request):
|
def put(self, request):
|
||||||
""" currently only used for mark all notifications seen
|
|
||||||
|
|
||||||
Permission checking:
|
|
||||||
1. login user.
|
|
||||||
"""
|
|
||||||
|
|
||||||
username = request.user.username
|
username = request.user.username
|
||||||
unseen_notices = SeadocNotification.objects.filter(username=username, seen=False)
|
unseen_notices = SeadocNotification.objects.filter(username=username, seen=False)
|
||||||
for notice in unseen_notices:
|
for notice in unseen_notices:
|
||||||
@@ -328,19 +330,22 @@ class AllNotificationsView(APIView):
|
|||||||
per_page = 25
|
per_page = 25
|
||||||
page = 1
|
page = 1
|
||||||
|
|
||||||
|
if page < 1:
|
||||||
|
error_msg = 'page invalid'
|
||||||
|
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||||
|
|
||||||
start = (page - 1) * per_page
|
start = (page - 1) * per_page
|
||||||
end = page * per_page
|
end = page * per_page
|
||||||
|
|
||||||
notice_list = UserNotification.objects.get_user_notifications(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)
|
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)
|
sdoc_result_notices = update_sdoc_notice_detail(request, sdoc_notice_list)
|
||||||
|
|
||||||
notification_list = []
|
notification_list = []
|
||||||
sdoc_notification_list = []
|
sdoc_notification_list = []
|
||||||
|
for i in general_result_notices:
|
||||||
for i in result_notices:
|
|
||||||
if i.detail is not None:
|
if i.detail is not None:
|
||||||
notice = {}
|
notice = {}
|
||||||
notice['id'] = i.id
|
notice['id'] = i.id
|
||||||
|
@@ -270,8 +270,8 @@ class SeadocNotificationManager(models.Manager):
|
|||||||
def delete_by_ids(self, doc_uuid, username, ids):
|
def delete_by_ids(self, doc_uuid, username, ids):
|
||||||
return self.filter(doc_uuid=doc_uuid, username=username, id__in=ids).delete()
|
return self.filter(doc_uuid=doc_uuid, username=username, id__in=ids).delete()
|
||||||
|
|
||||||
def list_all_by_user(self, username, start, end):
|
def list_all_by_user(self, username):
|
||||||
return self.filter(username=username).order_by('-created_at')[start: end]
|
return self.filter(username=username).order_by('-created_at')
|
||||||
|
|
||||||
def remove_user_notifications(self, username):
|
def remove_user_notifications(self, username):
|
||||||
""""Remove all user notifications."""
|
""""Remove all user notifications."""
|
||||||
|
Reference in New Issue
Block a user