Commit e8d93a88 by Chris Dodge

Add support in API to mark a notification as read

parent 89e51ecc
......@@ -40,6 +40,10 @@ from xmodule.modulestore import Location
from django.contrib.auth.models import User
from notification_prefs import NOTIFICATION_PREF_KEY
from edx_notifications.lib.publisher import register_notification_type, publish_notification_to_user
from edx_notifications.lib.consumer import get_notifications_count_for_user
from edx_notifications.data import NotificationMessage, NotificationType
MODULESTORE_CONFIG = mixed_store_config(settings.COMMON_TEST_DATA_ROOT, {}, include_xml=False)
TEST_API_KEY = str(uuid.uuid4())
......@@ -1874,3 +1878,33 @@ class UsersApiTests(ModuleStoreTestCase):
delete_uri = '{}invalid_role/courses/{}'.format(test_uri, unicode(self.course.id))
response = self.do_delete(delete_uri)
self.assertEqual(response.status_code, 404)
def test_mark_notification_as_read(self):
user_id = self._create_test_user()
msg_type = NotificationType(
name='open-edx.edx_notifications.lib.tests.test_publisher',
renderer='edx_notifications.renderers.basic.BasicSubjectBodyRenderer',
)
register_notification_type(msg_type)
msg = NotificationMessage(
namespace='test-runner',
msg_type=msg_type,
payload={
'foo': 'bar'
}
)
# now do happy path
sent_user_msg = publish_notification_to_user(user_id, msg)
# verify unread count
self.assertEqual(get_notifications_count_for_user(user_id, filters={'read': False}), 1)
# mark as read
test_uri = '{}/{}/notifications/{}/'.format(self.users_base_uri, user_id, sent_user_msg.msg.id)
response = self.do_post(test_uri, {"read": True})
self.assertEqual(response.status_code, 200)
# then verify unread count, which should be 0
self.assertEqual(get_notifications_count_for_user(user_id, filters={'read': False}), 0)
......@@ -26,6 +26,7 @@ urlpatterns = patterns(
url(r'^(?P<user_id>[a-zA-Z0-9]+)/roles/(?P<role>[a-z_]+)/courses/(?P<course_id>[a-zA-Z0-9_+\/:]+)$', users_views.UsersRolesCoursesDetail.as_view(), name='users-roles-courses-detail'),
url(r'^(?P<user_id>[a-zA-Z0-9]+)/roles/*$', users_views.UsersRolesList.as_view(), name='users-roles-list'),
url(r'^(?P<user_id>[a-zA-Z0-9]+)/workgroups/$', users_views.UsersWorkgroupsList.as_view(), name='users-workgroups-list'),
url(r'^(?P<user_id>[a-zA-Z0-9]+)/notifications/(?P<msg_id>[0-9]+)/$', users_views.UsersNotificationsDetail.as_view(), name='users-notifications-detail'),
url(r'^(?P<user_id>[a-zA-Z0-9]+)$', users_views.UsersDetail.as_view(), name='apimgr-users-detail'),
url(r'/*$^', users_views.UsersList.as_view(), name='apimgr-users-list'),
)
......
......@@ -57,7 +57,7 @@ from api_manager.utils import generate_base_uri, dict_has_items, extract_data_pa
from projects.serializers import BasicWorkgroupSerializer
from .serializers import UserSerializer, UserCountByCitySerializer, UserRolesSerializer
from edx_notifications.lib.consumer import mark_notification_read
log = logging.getLogger(__name__)
AUDIT_LOG = logging.getLogger("audit")
......@@ -1387,3 +1387,20 @@ class UsersRolesCoursesDetail(SecureAPIView):
return Response({}, status=status.HTTP_404_NOT_FOUND)
return Response({}, status=status.HTTP_204_NO_CONTENT)
class UsersNotificationsDetail(SecureAPIView):
"""
Allows for a caller to delete a user's notification, passed in by msg_id. Note that the
user_msg_id must belong to the user_id passed in
"""
def post(self, request, user_id, msg_id):
"""
POST /api/users/{user_id}/notifications/{msg_id}
"""
read = bool(request.DATA['read'])
mark_notification_read(int(user_id), int(msg_id), read=read)
return Response({}, status=status.HTTP_200_OK)
......@@ -602,9 +602,13 @@ NOTIFICATION_EMAIL_FROM_ADDRESS = ENV_TOKENS.get(
'NOTIFICATION_EMAIL_FROM_ADDRESS',
NOTIFICATION_EMAIL_FROM_ADDRESS
)
NOTIFICATION_EMAIL_CLICK_LINK_ROOT = ENV_TOKENS.get(
'NOTIFICATION_EMAIL_CLICK_LINK_ROOT',
NOTIFICATION_EMAIL_CLICK_LINK_ROOT
NOTIFICATION_APP_HOSTNAME = ENV_TOKENS.get(
'NOTIFICATION_APP_HOSTNAME',
SITE_NAME
)
NOTIFICATION_EMAIL_CLICK_LINK_URL_FORMAT = ENV_TOKENS.get(
'NOTIFICATION_EMAIL_CLICK_LINK_URL_FORMAT',
NOTIFICATION_EMAIL_CLICK_LINK_URL_FORMAT
)
NOTIFICATION_DIGEST_SEND_TIMEFILTERED = ENV_TOKENS.get(
'NOTIFICATION_DIGEST_SEND_TIMEFILTERED',
......
......@@ -2104,7 +2104,8 @@ NOTIFICATION_DAILY_DIGEST_SUBJECT = "Your unread notifications for '{display_nam
NOTIFICATION_WEEKLY_DIGEST_SUBJECT = "Your unread notifications for '{display_name}'"
NOTIFICATION_BRANDED_DEFAULT_LOGO = 'edx_notifications/img/edx-openedx-logo-tag.png'
NOTIFICATION_EMAIL_FROM_ADDRESS = ''
NOTIFICATION_EMAIL_CLICK_LINK_ROOT = 'http://localhost'
NOTIFICATION_APP_HOSTNAME = SITE_NAME
NOTIFICATION_EMAIL_CLICK_LINK_URL_FORMAT = "http://{hostname}{url_path}"
NOTIFICATION_DIGEST_SEND_TIMEFILTERED = True
# Country code overrides
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment