-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: master
Are you sure you want to change the base?
Email Notifications #324
Conversation
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 While you're doing the rebase, also look into 20311d7 as well, as this commit introduces a |
83e33fe
to
4849c3a
Compare
Things to review
|
34cd5b5
to
6cff64e
Compare
There was a problem hiding this 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.
csm_web/scheduler/migrations/0033_rename_subscribe_user_subscribed.py
Outdated
Show resolved
Hide resolved
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. |
b4ec3a5
to
2ab7cb3
Compare
Not sure what is going on with Cypress, but all the Django tests work. |
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') |
There was a problem hiding this comment.
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.
@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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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); | ||
}); | ||
}; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making False!
9523d1b
to
b0a5c3d
Compare
…lAPI with unsubscribe feature, error handling, and testing
b0a5c3d
to
6ff0b61
Compare
Implemented email notifications for the following views
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