Skip to content

Email Notifications #324

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Email Notifications #324

wants to merge 2 commits into from

Conversation

edwardneo
Copy link
Contributor

@edwardneo edwardneo commented Oct 1, 2022

Implemented email notifications for the following views

  • When a student adds themselves to a section: notification --> mentor and confirmation --> student
  • When a student swaps sections: notification --> mentor and confirmation --> student
  • When a student drops a section: notification --> mentor and confirmation --> student
  • When a student is forcibly dropped by a coordinator: notification --> mentor and notification --> student

Added mock classes for testing email functions and patching for tests that run the email functions
Added custom errors and error handling
Added new "subscribed" field to all users
Added profile tab and page containing subscribed toggle button

@smartspot2
Copy link
Member

smartspot2 commented Jan 15, 2023

FYI a868dc6 is a merge commit and should be amended with a rebase (either squash or amend the commit); try doing this before many other changes are added as well, otherwise it can be particularly frustrating to handle later on. This would also make rebasing onto master to get the latest updates a lot easier in the future as well. Additionally, db800d1 and 53bca4c are also merge commits, and should also be amended before marking the PR as ready for review.

For future reference, use git pull -r to pull with a rebase (git automatically pulls with a merge commit if there are conflicts or divergent branches), as it seems like the merge commit was made when you pulled changes after making a local commit.

While you're doing the rebase, also look into 20311d7 as well, as this commit introduces a package-lock.json version change from v2 to v1, which is what causes the huge diff in this PR; this change should be reverted. To prevent this from happening again in the future when you do an npm install, ensure you're using the latest LTS version of node (18.13.0, though anything 18.x should do); I recommend using nvm to manage your node versions.

@edwardneo edwardneo force-pushed the feat/notifications/main branch from 83e33fe to 4849c3a Compare January 20, 2023 08:32
@edwardneo edwardneo marked this pull request as ready for review January 20, 2023 08:35
@edwardneo
Copy link
Contributor Author

Things to review

  • Are all the emails necessary/written well?
  • Do we need to send an email to the mentor of the section a student swaps out of?
  • Is batching necessary?

Copy link
Member

@smartspot2 smartspot2 left a comment

Choose a reason for hiding this comment

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

The csm_web/scheduler/tests/test_emails.py is an empty file, and should probably be deleted.

Also, how does one test the API locally? There should probably be some kind of documentation written for this too—perhaps in the README.md in the repo, or perhaps in a wiki page in GitHub, etc.

Additionally, a lot of CI tests are failing, and it looks like it's because of missing dependencies; make sure you've added all of your new dependencies to the requirements files.

Otherwise, this looks pretty good overall; I haven't tested the actual functionality locally though, as I'm unsure how the credentials and access token are supposed to be set up.

@edwardneo
Copy link
Contributor Author

In general, I thought I fixed the branching issues with rebasing, but I suppose there are a lot of random loose ends. I'll take a more in depth look and a lot of these requests should be fixed after that.

@cypress
Copy link

cypress bot commented Feb 28, 2023

Passing run #96 ↗︎

0 78 0 0 Flakiness 0

Details:

Email Notifications
Project: csm_web Commit: 2ab7cb3f3d
Status: Passed Duration: 02:31 💡
Started: Mar 14, 2023 3:22 AM Ended: Mar 14, 2023 3:24 AM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

@edwardneo edwardneo force-pushed the feat/notifications/main branch from b4ec3a5 to 2ab7cb3 Compare March 14, 2023 03:19
@edwardneo
Copy link
Contributor Author

Not sure what is going on with Cypress, but all the Django tests work.

@edwardneo edwardneo requested a review from smartspot2 April 7, 2023 16:24
Comment on lines +191 to +194
def test_submit_attendance_failure(client, setup_section, word, mocker):
"""
Check that submitting an invalid word fails to update attendance.
"""
mocker.patch('scheduler.email.email_utils._email_send_message')
Copy link
Member

Choose a reason for hiding this comment

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

With these tests, there should also be an assertion that the _email_send_message function is actually called to send the email, if it's expected, and an assertion that it is not called if an email is not expected.

The tests could also be parameterized to include the different subscription settings from the user.

Comment on lines +27 to +32
@action(detail=True, methods=["PUT"])
def email(self, request, pk=None):
user = get_object_or_error(self.queryset, pk=pk)
user.subscribed = not user.subscribed
user.save()
return Response(status=status.HTTP_200_OK)
Copy link
Member

Choose a reason for hiding this comment

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

Generally, PUT requests should be idempotent; that is, repeated calls should have the exact same behavior as just one call. Here, flipping the user.subscribed variable each time the PUT request is sent goes against REST principles. Adding some field in the request body would be more conventional.

requirements.txt Outdated
Copy link
Member

Choose a reason for hiding this comment

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

When this branch is rebased onto master, these requirements should be moved to the pyproject.toml file, and the requirements should be re-exported from poetry.

Comment on lines 17 to 30
const loadUser = () => {
fetchJSON("/userinfo").then(userInfo => {
let priorityEnrollment = null;
if (userInfo.priorityEnrollment) {
priorityEnrollment = new Date(Date.parse(userInfo.priorityEnrollment));
}

const convertedUserInfo: UserInfo = {
...userInfo,
priorityEnrollment
};
setUserInfo(convertedUserInfo);
});
};
Copy link
Member

Choose a reason for hiding this comment

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

This should be put into a react-query hook instead, which will handle caching (and cache invalidation) for you.

className="csm-btn subscription-btn"
style={{ backgroundColor: `var(--csm-${userInfo?.subscribed ? "danger" : "green"})` }}
onClick={() => {
fetchWithMethod(`/users/${userInfo?.id}/email`, HTTP_METHODS.PUT).then(loadUser);
Copy link
Member

Choose a reason for hiding this comment

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

This should be put into a react-query mutation hook; in this hook you can invalidate the earlier GET request for the user's info.

@@ -36,6 +36,7 @@ def week_bounds(date):

class User(AbstractUser):
priority_enrollment = models.DateTimeField(null=True, blank=True)
subscribed = models.BooleanField(default=True, help_text="Email subscription status")
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we've had a conversation about the default here, but what was the reasoning for making this default to True?

It's both a good and a bad thing that people will get notifications for everything right off the bat; they'll be informed of all updates, but they'll also be spammed quite a bit (ex. a user may enroll and drop multiple sections and get an email for every single one of these actions, and the mentors will correspondingly be emailed those notifications as well.)

Having this be opt-in could be better for the amount of email traffic we use, and would also prevent unwanted spam from users. We aren't doing any marketing or anything, so we aren't really losing too much by making this be opt-in rather than opt-out.

I presume the concern was that people wouldn't know that this feature exists, but we can still advertise this feature during orientation, in announcements in slack, etc., as this is mostly helpful for mentors, as opposed to students. Maybe when waitlisting and section swapping are implemented, this could be more useful for students, but even then we can have messages displayed to students asking if they want to enable notifications when they waitlist for a section, or when they send out a request for a swap.

Also, there is also an opportunity here to be more fine-grained with the subscription configuration; there could be options for each possible email that is sent out. For example, a mentor that is also a student may not want any notifications about the sections they're enrolling in, but they do want notifications about students enrolling in their section. Or, a student may not want to receive any notifications about enrolling/dropping from sections, but they do want to receive notifications about waitlists or section swaps (when those come out).

Open to thoughts and discussion on this though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making False!

@faithdennis faithdennis force-pushed the feat/notifications/main branch from 9523d1b to b0a5c3d Compare April 1, 2025 01:42
…lAPI with unsubscribe feature, error handling, and testing
@faithdennis faithdennis force-pushed the feat/notifications/main branch from b0a5c3d to 6ff0b61 Compare April 6, 2025 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants