Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [FC-0047] add mobile push notifications functionality #34971

Conversation

NiedielnitsevIvan
Copy link
Contributor

Description

This PR addressed to adding the ability to send push notifications to the OeX mobile app on IOS and Android, using edx-ace functionality and Firebase Cloud Messaging as a cloud provider.

Some push notifications are also added here directly, namely:

  • push notifications for user enroll;
  • push notifications for user unenroll;
  • push notifications for add course beta testers;
  • push notifications for remove course beta testers;
  • push notification event to discussions.

Useful information to include:

  • Which edX user roles will this change impact? Common user roles are "Learner", "Course Author",
    "Developer", and "Operator".
  • Include screenshots for changes to the UI (ideally, both "before" and "after" screenshots, if applicable).
  • Provide links to the description of corresponding configuration changes. Remember to correctly annotate these
    changes.

Supporting information

FC-0047
TBD

Testing instructions

  1. Install edx-ace version 1.9.0.
  2. Add FIREBASE_CREDENTIALS or FIREBASE_CREDENTIALS_PATH to the platform settings.
  3. Add a new push_notification channel to ACE_ENABLED_CHANEL.
  4. Log in to OeX.
  5. Install the OeX mobile application on your device.
  6. Add your device token to FCM Devices with a link to your user from the admin panel.
  7. Enroll/unenroll the user(from step 7) in the “Instructor” tab to trigger the push notification event.
  8. Make sure you receive push notifications on your device.

Deadline

"None"

Other information

@NiedielnitsevIvan NiedielnitsevIvan requested a review from a team as a code owner June 11, 2024 15:03
@openedx-webhooks
Copy link

openedx-webhooks commented Jun 11, 2024

Thanks for the pull request, @NiedielnitsevIvan!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/wg-maintenance-edx-platform. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jun 11, 2024
@NiedielnitsevIvan NiedielnitsevIvan changed the title feat: [FC-0047] add settings for edx-ace push notifications feat: [FC-0047] add mobile push notifications functionality Jun 11, 2024
@NiedielnitsevIvan NiedielnitsevIvan force-pushed the NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel branch 3 times, most recently from e9e1876 to b325343 Compare June 12, 2024 17:24
@NiedielnitsevIvan NiedielnitsevIvan marked this pull request as draft June 13, 2024 15:05
@NiedielnitsevIvan
Copy link
Contributor Author

To fix pipelines, it is necessary to merge this PR in edx-ace and release a new version so that this PR can rely on it.

@NiedielnitsevIvan NiedielnitsevIvan force-pushed the NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel branch from eef6da0 to b8c6acb Compare July 3, 2024 07:15
@NiedielnitsevIvan NiedielnitsevIvan force-pushed the NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel branch from a437349 to 2718724 Compare July 30, 2024 17:23
@NiedielnitsevIvan NiedielnitsevIvan marked this pull request as ready for review July 30, 2024 17:23
@mphilbrick211 mphilbrick211 added the FC Relates to an Axim Funded Contribution project label Jul 30, 2024
@NiedielnitsevIvan NiedielnitsevIvan force-pushed the NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel branch 2 times, most recently from be2bc82 to 0d08485 Compare August 5, 2024 08:31
@GlugovGrGlib GlugovGrGlib force-pushed the NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel branch from 0d08485 to 46082e8 Compare August 5, 2024 17:47
Copy link
Member

@OmarIthawi OmarIthawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contirbution.

I've added a review a long while ago, but for some reasons it's not showing up.

Please let me know whant do you think about the suggested change.

Comment on lines 78 to 81
class CommentNotification(BaseMessageType):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.options['transactional'] = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transactioanl should be used for important emails like password reset and others. I think in this case, CommentNotification isn't transactional

Suggested change
class CommentNotification(BaseMessageType):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.options['transactional'] = True
class CommentNotification(BaseMessageType):
pass

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks.

Comment on lines +1 to +3
{% load i18n %}
{% blocktrans trimmed %}{{ comment_username }} commented to {{ thread_title }}:{% endblocktrans %}
{{ comment_body_text }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the message reach the device with a new line before {{ comment_body_text }} or would it be converted to a space.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be converted to a space.

@@ -0,0 +1,2 @@
{% load i18n %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to title.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed.

@@ -19,7 +19,7 @@
import openedx.core.djangoapps.django_comment_common.comment_client as cc
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from lms.djangoapps.discussion.signals.handlers import ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY
from lms.djangoapps.discussion.tasks import _should_send_message, _track_notification_sent
from lms.djangoapps.discussion.tasks import _is_first_comment, _should_send_message, _track_notification_sent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider breaking into new lines

Suggested change
from lms.djangoapps.discussion.tasks import _is_first_comment, _should_send_message, _track_notification_sent
from lms.djangoapps.discussion.tasks import (
_is_first_comment,
_should_send_message,
_track_notification_sent,
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

assert actual_result is False

should_email_send = _is_first_comment(comment_dict['id'], thread['id'])
assert should_email_send is False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert should_email_send is False
assert not should_email_send

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

Comment on lines 144 to 145
if email_params:
email_params.update({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using message_params instead to be less confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

from rest_framework import status
from rest_framework.response import Response

from edx_ace.push_notifications.views import GCMDeviceViewSet as GCMDeviceViewSetBase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a link to those classes, I couldn't find those in openedx/edx-ace#282

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is imported from django-push-notifications into edx-ace so that there is no direct dependency, and in case of need, it can be changed in edx-ace without changing the implementation in the platform.

https://github.com/openedx/edx-ace/blob/master/edx_ace/push_notifications/views/__init__.py



@mobile_view()
class GCMDeviceViewSet(GCMDeviceViewSetBase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the security controls for this view?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default for mobile_view decorator:

authentication_classes = (
    JwtAuthentication,
    BearerAuthenticationAllowInactiveUser,
    SessionAuthenticationAllowInactiveUser
)
permission_classes = (IsAuthenticated,)

@NiedielnitsevIvan NiedielnitsevIvan force-pushed the NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel branch from 46082e8 to cdbdd8c Compare August 9, 2024 09:50
@GlugovGrGlib GlugovGrGlib force-pushed the NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel branch from 61c2aca to d88d880 Compare August 10, 2024 13:22
@OmarIthawi
Copy link
Member

@NiedielnitsevIvan @GlugovGrGlib I see you're still actively pushing changes to this branch. Thank you for your efforts!

Is there anything I can help with to push this work forward? I know I've delayed other pull requests so I want to double check that I'm not blocking this one.

@GlugovGrGlib
Copy link
Member

GlugovGrGlib commented Aug 11, 2024

Hello @OmarIthawi with this latest commits we were able to address your comments from previous CR run and make all CI checks to pass. This PR is ready for the yet another review, hopefully final CR pass from your side.

@GlugovGrGlib GlugovGrGlib force-pushed the NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel branch from a1dcec7 to 480ccca Compare August 16, 2024 12:58
Copy link
Member

@OmarIthawi OmarIthawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NiedielnitsevIvan you've done a really good job by refactoring the email --> message.

Thank you so much. This is very helpful. The pull request looks good and frankly ready to be merged.

I've added many small notes please check them.

Push notificaiton messages review

I recommend merging this pull request just to avoid any more delays and conflicts.

However, with all due respect, I think there's a little effort went into reviewing the UX of the notification messages. It's alright we're all engineers and aren't masters in business communications.

Therefore I recommend after merging this pull request, having someone with a User Experience skills and/or product management to review the push notification messages to ensure it's up to the current standards and provides an adequate experience to the user on their phone (cc: @e0d).

Comment on lines 78 to 82
class CommentNotification(BaseMessageType):
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class CommentNotification(BaseMessageType):
pass
class CommentNotification(BaseMessageType):
"""
Notify discussion participants of new comments.
"""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans trimmed %}{{ comment_username }} replied to {{ thread_title }}{% endblocktrans %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we're not including any excerpt? Depending on how much mobile notifications limit we have in mobile phones.

I'd recommed to add the comment's first 200 characters or so:

Suggested change
{% blocktrans trimmed %}{{ comment_username }} replied to {{ thread_title }}{% endblocktrans %}
{% blocktrans trimmed %}{{ comment_username }} replied to {{ thread_title }}: {{ comment_body_excerpt }}{% endblocktrans %}

comment_body_excerpt would be either the whole comment or part of it ending with ....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, this was not in the text of the push notifications when they were approved, but if you insist, I added it.

from .views import GCMDeviceViewSet


CREATE_GCM_DEVICE = GCMDeviceViewSet.as_view({'post': 'create'})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CREATE_GCM_DEVICE = GCMDeviceViewSet.as_view({'post': 'create'})
create_gcm_device_post_view = GCMDeviceViewSet.as_view({'post': 'create'})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

Comment on lines 8 to 12
CREATE_GCM_DEVICE = GCMDeviceViewSet.as_view({'post': 'create'})


urlpatterns = [
path('create-token/', CREATE_GCM_DEVICE, name='gcmdevice-list'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CREATE_GCM_DEVICE = GCMDeviceViewSet.as_view({'post': 'create'})
urlpatterns = [
path('create-token/', CREATE_GCM_DEVICE, name='gcmdevice-list'),
CREATE_GCM_DEVICE = GCMDeviceViewSet.as_view({'post': 'create'})
urlpatterns = [
path('create-token/', create_gcm_device_post_view, name='gcmdevice-list'),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

@@ -0,0 +1,5 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Dear Student,{% endblocktrans %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formality isn't ideal in mobile in my opinion.

Suggested change
{% blocktrans %}Dear Student,{% endblocktrans %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@@ -0,0 +1,5 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Dear student,{% endblocktrans %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{% blocktrans %}Dear student,{% endblocktrans %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Comment on lines 13 to 14
try:
import firebase_admin # pylint: disable=import-outside-toplevel
except ImportError:
log.error('Could not import firebase_admin package.')
return

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a core import that should be kept is a real import since the package is installed always in the requirements.

Suggested change
try:
import firebase_admin # pylint: disable=import-outside-toplevel
except ImportError:
log.error('Could not import firebase_admin package.')
return
import firebase_admin # pylint: disable=import-outside-toplevel

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

NiedielnitsevIvan and others added 2 commits September 5, 2024 15:29
feat: [FC-0047] Add push notifications for user enroll

feat: [FC-0047] Add push notifications for user unenroll

feat: [FC-0047] Add push notifications for add course beta testers

feat: [FC-0047] Add push notifications for remove course beta testers

feat: [FC-0047] Add push notification event to discussions
@NiedielnitsevIvan NiedielnitsevIvan force-pushed the NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel branch from 480ccca to a6c1ebf Compare September 6, 2024 14:41
@NiedielnitsevIvan NiedielnitsevIvan force-pushed the NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel branch from a6c1ebf to eef99a6 Compare September 6, 2024 14:45
@OmarIthawi
Copy link
Member

@NiedielnitsevIvan thank you so much for going above and beyond. Please let me know when the tests are fixed so we can go ahead and merge it.

…cations-chanel' of github.com:raccoongang/edx-platform into NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel
@NiedielnitsevIvan
Copy link
Contributor Author

@NiedielnitsevIvan thank you so much for going above and beyond. Please let me know when the tests are fixed so we can go ahead and merge it.

@OmarIthawi Checks are fixed.

Copy link
Member

@OmarIthawi OmarIthawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @NiedielnitsevIvan! Looks good to me since last time, now the tests are fixed I give it ✅

@GlugovGrGlib
Copy link
Member

@bmtcril as this PR is finally approved, could you please check and merge this PR?

@bmtcril
Copy link
Contributor

bmtcril commented Sep 13, 2024

Thanks @GlugovGrGlib @NiedielnitsevIvan , I'm doing a last pass run through now. This seems to me to be a medium risk PR to land, so what I'd like to do is:

  • Notify 2U in the usual cc-edx-platform channel that this is coming and give them time to review / ask questions
  • Try to schedule time when one of you can be available to do the merge in case of any issues / reverts
  • We often hold off from doing these merges on a Friday, is there I time during 2U business hours on Monday I can suggest merging?

Thanks, this is looking great!

Copy link
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested LMS functionality locally, though I don't have the ability to actually trigger push notifications at this point I was able to confirm that things worked both with the new settings set and without them.

@bmtcril
Copy link
Contributor

bmtcril commented Sep 16, 2024

Merging on this is delayed while 2U works out issues on their side. Better to let the release queue clear than potentially get caught up in rollbacks and reverts while things get stable there. Discussion is happening in #cc-edx-platform if you'd like to follow along, but it seems likely it will take a day or two before we can merge. Sorry for the delay.

@bmtcril bmtcril merged commit 471bdd2 into openedx:master Sep 20, 2024
49 checks passed
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

@GlugovGrGlib GlugovGrGlib deleted the NiedielnitsevIvan/FC-0047/feature/implement-push-notifications-chanel branch October 1, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

7 participants