Skip to content

Commit

Permalink
urban airship push notification support
Browse files Browse the repository at this point in the history
updated edx-notifications version

send course announcements to urban airship too
  • Loading branch information
ziafazal committed Aug 23, 2017
1 parent 9217a8b commit a05d7de
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
8 changes: 8 additions & 0 deletions cms/djangoapps/contentstore/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
Expand Down
23 changes: 0 additions & 23 deletions cms/djangoapps/contentstore/views/tests/test_course_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 7 additions & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {}
Expand Down
6 changes: 6 additions & 0 deletions common/djangoapps/student/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a05d7de

Please sign in to comment.