mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 07:27:04 +00:00
update set_notices_seen
This commit is contained in:
@@ -17,6 +17,11 @@ class NotificationsView(APIView):
|
|||||||
throttle_classes = (UserRateThrottle,)
|
throttle_classes = (UserRateThrottle,)
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
""" currently only used for get unseen notifications count
|
||||||
|
|
||||||
|
Permission checking:
|
||||||
|
1. login user.
|
||||||
|
"""
|
||||||
|
|
||||||
username = request.user.username
|
username = request.user.username
|
||||||
unseen_count = UserNotification.objects.count_unseen_user_notifications(username)
|
unseen_count = UserNotification.objects.count_unseen_user_notifications(username)
|
||||||
@@ -24,3 +29,26 @@ class NotificationsView(APIView):
|
|||||||
result['unseen_count'] = unseen_count
|
result['unseen_count'] = unseen_count
|
||||||
|
|
||||||
return Response(result)
|
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 = UserNotification.objects.get_user_notifications(username,
|
||||||
|
seen=False)
|
||||||
|
for notice in unseen_notices:
|
||||||
|
notice.seen = True
|
||||||
|
notice.save()
|
||||||
|
|
||||||
|
# TODO mark related user msg as read
|
||||||
|
if notice.is_user_message():
|
||||||
|
d = notice.user_message_detail_to_dict()
|
||||||
|
msg_from = d.get('msg_from')
|
||||||
|
from seahub.message.models import UserMessage
|
||||||
|
UserMessage.objects.update_unread_messages(msg_from, username)
|
||||||
|
|
||||||
|
return Response({'success': True})
|
||||||
|
@@ -43,8 +43,8 @@ $('#mark-all-read').click(function() {
|
|||||||
var unread_items = $('#notices-table .unread');
|
var unread_items = $('#notices-table .unread');
|
||||||
if (unread_items.length > 0) {
|
if (unread_items.length > 0) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '{% url 'set_notices_seen' %}',
|
url: "{% url 'api-v2.1-notifications' %}",
|
||||||
type: 'POST',
|
type: 'PUT',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
beforeSend: prepareCSRFToken,
|
beforeSend: prepareCSRFToken,
|
||||||
success: function() {
|
success: function() {
|
||||||
|
@@ -162,7 +162,6 @@ urlpatterns = patterns(
|
|||||||
url(r'^ajax/unenc-rw-repos/$', unenc_rw_repos, name='unenc_rw_repos'),
|
url(r'^ajax/unenc-rw-repos/$', unenc_rw_repos, name='unenc_rw_repos'),
|
||||||
url(r'^ajax/upload-file-done/$', upload_file_done, name='upload_file_done'),
|
url(r'^ajax/upload-file-done/$', upload_file_done, name='upload_file_done'),
|
||||||
url(r'^ajax/get_popup_notices/$', get_popup_notices, name='get_popup_notices'),
|
url(r'^ajax/get_popup_notices/$', get_popup_notices, name='get_popup_notices'),
|
||||||
url(r'^ajax/set_notices_seen/$', set_notices_seen, name='set_notices_seen'),
|
|
||||||
url(r'^ajax/set_notice_seen_by_id/$', set_notice_seen_by_id, name='set_notice_seen_by_id'),
|
url(r'^ajax/set_notice_seen_by_id/$', set_notice_seen_by_id, name='set_notice_seen_by_id'),
|
||||||
url(r'^ajax/space_and_traffic/$', space_and_traffic, name='space_and_traffic'),
|
url(r'^ajax/space_and_traffic/$', space_and_traffic, name='space_and_traffic'),
|
||||||
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/setting/change-passwd/$', ajax_repo_change_passwd, name='ajax_repo_change_passwd'),
|
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/setting/change-passwd/$', ajax_repo_change_passwd, name='ajax_repo_change_passwd'),
|
||||||
@@ -200,13 +199,13 @@ urlpatterns = patterns(
|
|||||||
url(r'^api/v2.1/query-zip-progress/$', QueryZipProgressView.as_view(), name='api-v2.1-query-zip-progress'),
|
url(r'^api/v2.1/query-zip-progress/$', QueryZipProgressView.as_view(), name='api-v2.1-query-zip-progress'),
|
||||||
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/dir/$', DirView.as_view(), name='api-v2.1-dir-view'),
|
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/dir/$', DirView.as_view(), name='api-v2.1-dir-view'),
|
||||||
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/set-password/$', RepoSetPassword.as_view(), name="api-v2.1-repo-set-password"),
|
url(r'^api/v2.1/repos/(?P<repo_id>[-0-9a-f]{36})/set-password/$', RepoSetPassword.as_view(), name="api-v2.1-repo-set-password"),
|
||||||
|
url(r'^api/v2.1/invitations/$', InvitationsView.as_view()),
|
||||||
|
url(r'^api/v2.1/invitations/(?P<token>[a-f0-9]{32})/$', InvitationView.as_view()),
|
||||||
|
url(r'^api/v2.1/notifications/$', NotificationsView.as_view(), name='api-v2.1-notifications'),
|
||||||
|
|
||||||
url(r'^api/v2.1/admin/sysinfo/$', SysInfo.as_view(), name='api-v2.1-sysinfo'),
|
url(r'^api/v2.1/admin/sysinfo/$', SysInfo.as_view(), name='api-v2.1-sysinfo'),
|
||||||
url(r'^api/v2.1/admin/devices/$', AdminDevices.as_view(), name='api-v2.1-admin-devices'),
|
url(r'^api/v2.1/admin/devices/$', AdminDevices.as_view(), name='api-v2.1-admin-devices'),
|
||||||
url(r'^api/v2.1/admin/device-errors/$', AdminDeviceErrors.as_view(), name='api-v2.1-admin-device-errors'),
|
url(r'^api/v2.1/admin/device-errors/$', AdminDeviceErrors.as_view(), name='api-v2.1-admin-device-errors'),
|
||||||
url(r'^api/v2.1/invitations/$', InvitationsView.as_view()),
|
|
||||||
url(r'^api/v2.1/invitations/(?P<token>[a-f0-9]{32})/$', InvitationView.as_view()),
|
|
||||||
url(r'^api/v2.1/notifications/$', NotificationsView.as_view()),
|
|
||||||
|
|
||||||
url(r'^api/v2.1/admin/libraries/$', AdminLibraries.as_view(), name='api-v2.1-admin-libraries'),
|
url(r'^api/v2.1/admin/libraries/$', AdminLibraries.as_view(), name='api-v2.1-admin-libraries'),
|
||||||
url(r'^api/v2.1/admin/libraries/(?P<repo_id>[-0-9a-f]{36})/$', AdminLibrary.as_view(), name='api-v2.1-admin-library'),
|
url(r'^api/v2.1/admin/libraries/(?P<repo_id>[-0-9a-f]{36})/$', AdminLibrary.as_view(), name='api-v2.1-admin-library'),
|
||||||
url(r'^api/v2.1/admin/libraries/(?P<repo_id>[-0-9a-f]{36})/dirents/$', AdminLibraryDirents.as_view(), name='api-v2.1-admin-library-dirents'),
|
url(r'^api/v2.1/admin/libraries/(?P<repo_id>[-0-9a-f]{36})/dirents/$', AdminLibraryDirents.as_view(), name='api-v2.1-admin-library-dirents'),
|
||||||
|
@@ -1255,31 +1255,6 @@ def get_popup_notices(request):
|
|||||||
"notice_html": notice_html,
|
"notice_html": notice_html,
|
||||||
}), content_type=content_type)
|
}), content_type=content_type)
|
||||||
|
|
||||||
@login_required_ajax
|
|
||||||
@require_POST
|
|
||||||
def set_notices_seen(request):
|
|
||||||
"""Set user's notices seen:
|
|
||||||
|
|
||||||
Arguments:
|
|
||||||
- `request`:
|
|
||||||
"""
|
|
||||||
content_type = 'application/json; charset=utf-8'
|
|
||||||
username = request.user.username
|
|
||||||
|
|
||||||
unseen_notices = UserNotification.objects.get_user_notifications(username,
|
|
||||||
seen=False)
|
|
||||||
for notice in unseen_notices:
|
|
||||||
notice.seen = True
|
|
||||||
notice.save()
|
|
||||||
|
|
||||||
# mark related user msg as read
|
|
||||||
if notice.is_user_message():
|
|
||||||
d = notice.user_message_detail_to_dict()
|
|
||||||
msg_from = d.get('msg_from')
|
|
||||||
UserMessage.objects.update_unread_messages(msg_from, username)
|
|
||||||
|
|
||||||
return HttpResponse(json.dumps({'success': True}), content_type=content_type)
|
|
||||||
|
|
||||||
@login_required_ajax
|
@login_required_ajax
|
||||||
@require_POST
|
@require_POST
|
||||||
def set_notice_seen_by_id(request):
|
def set_notice_seen_by_id(request):
|
||||||
|
@@ -123,8 +123,8 @@ define([
|
|||||||
if (this.$(".unread").length > 0) {
|
if (this.$(".unread").length > 0) {
|
||||||
// set all unread notice to be read
|
// set all unread notice to be read
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: Common.getUrl({name: 'set_notices_seen'}),
|
url: Common.getUrl({name: 'notifications'}),
|
||||||
type: 'POST',
|
type: 'PUT',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
beforeSend: Common.prepareCSRFToken,
|
beforeSend: Common.prepareCSRFToken,
|
||||||
success: function() {
|
success: function() {
|
||||||
|
@@ -157,9 +157,10 @@ define([
|
|||||||
// Misc
|
// Misc
|
||||||
case 'thumbnail_create': return siteRoot + 'thumbnail/' + options.repo_id + '/create/';
|
case 'thumbnail_create': return siteRoot + 'thumbnail/' + options.repo_id + '/create/';
|
||||||
case 'get_popup_notices': return siteRoot + 'ajax/get_popup_notices/';
|
case 'get_popup_notices': return siteRoot + 'ajax/get_popup_notices/';
|
||||||
case 'set_notices_seen': return siteRoot + 'ajax/set_notices_seen/';
|
|
||||||
case 'notifications': return siteRoot + 'api/v2.1/notifications/';
|
case 'notifications': return siteRoot + 'api/v2.1/notifications/';
|
||||||
case 'set_notice_seen_by_id': return siteRoot + 'ajax/set_notice_seen_by_id/';
|
case 'set_notice_seen_by_id': return siteRoot + 'ajax/set_notice_seen_by_id/';
|
||||||
|
|
||||||
case 'toggle_personal_modules': return siteRoot + 'ajax/toggle-personal-modules/';
|
case 'toggle_personal_modules': return siteRoot + 'ajax/toggle-personal-modules/';
|
||||||
case 'starred_files': return siteRoot + 'api2/starredfiles/';
|
case 'starred_files': return siteRoot + 'api2/starredfiles/';
|
||||||
case 'events': return siteRoot + 'api2/events/';
|
case 'events': return siteRoot + 'api2/events/';
|
||||||
|
@@ -9,9 +9,9 @@ class InvitationsTest(BaseTestCase):
|
|||||||
|
|
||||||
def test_can_get_unseen_count(self):
|
def test_can_get_unseen_count(self):
|
||||||
|
|
||||||
self.login_as(self.user)
|
|
||||||
|
|
||||||
UserNotification.objects.add_file_uploaded_msg(self.username, 'test')
|
UserNotification.objects.add_file_uploaded_msg(self.username, 'test')
|
||||||
|
|
||||||
|
self.login_as(self.user)
|
||||||
resp = self.client.get(self.endpoint)
|
resp = self.client.get(self.endpoint)
|
||||||
self.assertEqual(200, resp.status_code)
|
self.assertEqual(200, resp.status_code)
|
||||||
|
|
||||||
@@ -22,3 +22,23 @@ class InvitationsTest(BaseTestCase):
|
|||||||
|
|
||||||
resp = self.client.get(self.endpoint)
|
resp = self.client.get(self.endpoint)
|
||||||
self.assertEqual(403, resp.status_code)
|
self.assertEqual(403, resp.status_code)
|
||||||
|
|
||||||
|
def test_can_unseen_all_notifications(self):
|
||||||
|
|
||||||
|
UserNotification.objects.add_file_uploaded_msg(self.username, 'test')
|
||||||
|
assert UserNotification.objects.count_unseen_user_notifications(self.username) == 1
|
||||||
|
|
||||||
|
self.login_as(self.user)
|
||||||
|
resp = self.client.put(self.endpoint, {}, 'application/x-www-form-urlencoded')
|
||||||
|
self.assertEqual(200, resp.status_code)
|
||||||
|
|
||||||
|
assert UserNotification.objects.count_unseen_user_notifications(self.username) == 0
|
||||||
|
|
||||||
|
def test_unseen_notifications_with_invalid_user_permission(self):
|
||||||
|
|
||||||
|
UserNotification.objects.add_file_uploaded_msg(self.username, 'test')
|
||||||
|
assert UserNotification.objects.count_unseen_user_notifications(self.username) == 1
|
||||||
|
|
||||||
|
resp = self.client.put(self.endpoint, {}, 'application/x-www-form-urlencoded')
|
||||||
|
self.assertEqual(403, resp.status_code)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user