From a05d7dedee4c2c50b48239c393756939b2ce916e Mon Sep 17 00:00:00 2001 From: Zia Fazal Date: Wed, 23 Aug 2017 14:02:27 +0500 Subject: [PATCH] urban airship push notification support updated edx-notifications version send course announcements to urban airship too --- cms/djangoapps/contentstore/views/course.py | 8 +++++++ .../views/tests/test_course_updates.py | 23 ------------------- cms/envs/common.py | 7 ++++++ common/djangoapps/student/tasks.py | 6 +++++ requirements/edx/custom.txt | 2 +- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index b46ba1f64399..6b301a5e01c9 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -6,6 +6,7 @@ import logging import random import string # pylint: disable=deprecated-module +import dateutil.parser from bs4 import BeautifulSoup from django.conf import settings @@ -1006,6 +1007,11 @@ def course_info_update_handler(request, course_key_string, provided_id=None): max_len = getattr(settings, 'NOTIFICATIONS_MAX_EXCERPT_LEN', 65) if len(excerpt) > max_len: excerpt = "{}...".format(excerpt[:max_len]) + announcement_open_url = "https://{site_name}/courses/{course_id}/announcements/{date}/".format( + site_name=settings.SITE_NAME, + course_id=unicode(course_key), + date=dateutil.parser.parse(announcement_date).strftime('%m/%d/%Y'), + ) notification_msg = NotificationMessage( msg_type=notification_type, @@ -1014,6 +1020,8 @@ def course_info_update_handler(request, course_key_string, provided_id=None): '_schema_version': '1', 'course_name': course.display_name, 'excerpt': excerpt, + 'tag_group': 'enrollments', + 'open_url': announcement_open_url, 'announcement_date': announcement_date, 'title': title, } diff --git a/cms/djangoapps/contentstore/views/tests/test_course_updates.py b/cms/djangoapps/contentstore/views/tests/test_course_updates.py index 586c1e107f70..ab023f4714d8 100644 --- a/cms/djangoapps/contentstore/views/tests/test_course_updates.py +++ b/cms/djangoapps/contentstore/views/tests/test_course_updates.py @@ -153,29 +153,6 @@ def test_notifications_enabled_when_new_updates_in_course(self): self.assertTrue(get_notifications_count_for_user(test_user_1.id), 1) self.assertTrue(get_notifications_count_for_user(test_user_2.id), 1) - @patch.dict("django.conf.settings.FEATURES", {"ENABLE_NOTIFICATIONS": True}) - def test_notifications_enabled_when_new_updates_in_course(self): - # create new users and enroll them in the course. - test_user_1 = UserFactory.create(password='test_pass') - CourseEnrollmentFactory(user=test_user_1, course_id=self.course.id) - test_user_2 = UserFactory.create(password='test_pass') - CourseEnrollmentFactory(user=test_user_2, course_id=self.course.id) - - content = 'Test update' - payload = {'content': content, 'date': 'Feb 19, 2015'} - url = self.create_update_url() - - resp = self.client.ajax_post( - url, payload, REQUEST_METHOD="POST" - ) - self.assertEqual(resp.status_code, 200) - self.assertHTMLEqual(content, json.loads(resp.content)['content']) - - # now the enrolled users should get notification about the - # course update where they are enrolled as student. - self.assertTrue(get_notifications_count_for_user(test_user_1.id), 1) - self.assertTrue(get_notifications_count_for_user(test_user_2.id), 1) - def test_course_updates_compatibility(self): ''' Test that course updates doesn't break on old data (content in 'data' field). diff --git a/cms/envs/common.py b/cms/envs/common.py index d0b260526fc7..c8ed829f08da 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -1244,6 +1244,13 @@ } } }, + 'urban-airship': { + 'class': 'edx_notifications.channels.urban_airship.UrbanAirshipNotificationChannelProvider', + 'options': { + 'application_id': 'test_api_key', + 'rest_api_key': 'test_api_key', + } + }, 'null': { 'class': 'edx_notifications.channels.null.NullNotificationChannel', 'options': {} diff --git a/common/djangoapps/student/tasks.py b/common/djangoapps/student/tasks.py index fa33c5ff8b3b..de0902bbba81 100644 --- a/common/djangoapps/student/tasks.py +++ b/common/djangoapps/student/tasks.py @@ -67,6 +67,12 @@ def publish_course_notifications_task(course_id, notification_msg, exclude_user_ try: bulk_publish_notification_to_users(user_ids, notification_msg, exclude_user_ids=exclude_user_ids) + # if we have a course announcement notification publish it to urban airship too + if notification_msg.msg_type.name == 'open-edx.studio.announcements.new-announcement': + bulk_publish_notification_to_users( + user_ids, notification_msg, exclude_user_ids=exclude_user_ids, preferred_channel='urban-airship' + ) + except Exception, ex: # Notifications are never critical, so we don't want to disrupt any # other logic processing. So log and continue. diff --git a/requirements/edx/custom.txt b/requirements/edx/custom.txt index e299195106c7..ced24ed0f01b 100644 --- a/requirements/edx/custom.txt +++ b/requirements/edx/custom.txt @@ -10,7 +10,7 @@ -e git+https://github.com/edx-solutions/xblock-adventure.git@7bdeb62b1055377dc04a7b503f7eea8264f5847b#egg=xblock-adventure # This is currently using a custom branch: https://github.com/open-craft/xblock-poll/tree/copy-change-patch -e git+https://github.com/open-craft/xblock-poll.git@3a06ef4782f9f90d6a8594c4eb4a84a277182fb8#egg=xblock-poll --e git+https://github.com/edx/edx-notifications.git@0.6.0#egg=edx-notifications==0.6.0 +-e git+https://github.com/edx/edx-notifications.git@0.6.1#egg=edx-notifications==0.6.1 -e git+https://github.com/open-craft/problem-builder.git@v2.7.2#egg=xblock-problem-builder==2.7.2 -e git+https://github.com/OfficeDev/xblock-officemix.git@86238f5968a08db005717dbddc346808f1ed3716#egg=xblock-officemix -e git+https://github.com/open-craft/xblock-chat.git@ad0b7627bfd2d135e1776e19ce208ecf517e50c5#egg=xblock-chat