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: add push notifications #1704

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ package-lock.json
# Virtual environments
venv/
.venv/

# Webpush
/keys/webpush/
/keys/

# Keys
*.pem
3 changes: 3 additions & 0 deletions config/docker/initial_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ echo -e "${BLUE}${BOLD}Creating eighth period blocks...${CLEAR}"
python3 create_blocks.py -l A B -c 60
python3 create_blocks.py -l A B C -i 4 -c 15

echo -e "${BLUE}${BOLD}Generating vapid keys...${CLEAR}"
python3 create_vapid_keys.py

echo -e "${BLUE}${BOLD}Cleaning up scripts...${CLEAR}"
for file in config/scripts/*.py; do
rm "$(basename "$file")"
Expand Down
25 changes: 25 additions & 0 deletions config/scripts/create_vapid_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import base64
import os

from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
from py_vapid import Vapid

PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
os.makedirs(os.path.join(PROJECT_ROOT, "keys", "webpush"))

# Generate VAPID key pair
vapid = Vapid()
vapid.generate_keys()

# Get public and private keys for the vapid key pair
vapid.save_public_key(os.path.join(PROJECT_ROOT, "keys", "webpush", "public_key.pem"))
public_key_bytes = vapid.public_key.public_bytes(Encoding.X962, PublicFormat.UncompressedPoint)

vapid.save_key(os.path.join(PROJECT_ROOT, "keys", "webpush", "private_key.pem"))


# Convert the public key to applicationServerKey format
application_server_key = base64.urlsafe_b64encode(public_key_bytes).replace(b"=", b"").decode("utf8")

with open(os.path.join(PROJECT_ROOT, "keys", "webpush", "ApplicationServerKey.key"), "w", encoding="utf-8") as f:
f.write(application_server_key)
3 changes: 2 additions & 1 deletion cron/eighth-absence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
timestamp=$(date +"%Y-%m-%d-%H%M")
cd /usr/local/www/intranet3
./cron/env.sh ./manage.py absence_email --silent
echo "Absence email sent at $timestamp." >> /var/log/ion/email.log
./cron/env.sh ./manage.py absence_notify --silent
echo "Absence email and push notification sent at $timestamp." >> /var/log/ion/email.log
96 changes: 96 additions & 0 deletions docs/sourcedoc/intranet.apps.announcements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,102 @@ intranet.apps.announcements.views module
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_BACKUP\_1087 module
------------------------------------------------------

.. automodule:: intranet.apps.announcements.views_BACKUP_1087
:members:
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_BACKUP\_1114 module
------------------------------------------------------

.. automodule:: intranet.apps.announcements.views_BACKUP_1114
:members:
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_BACKUP\_1972 module
------------------------------------------------------

.. automodule:: intranet.apps.announcements.views_BACKUP_1972
:members:
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_BASE\_1087 module
----------------------------------------------------

.. automodule:: intranet.apps.announcements.views_BASE_1087
:members:
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_BASE\_1114 module
----------------------------------------------------

.. automodule:: intranet.apps.announcements.views_BASE_1114
:members:
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_BASE\_1972 module
----------------------------------------------------

.. automodule:: intranet.apps.announcements.views_BASE_1972
:members:
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_LOCAL\_1087 module
-----------------------------------------------------

.. automodule:: intranet.apps.announcements.views_LOCAL_1087
:members:
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_LOCAL\_1114 module
-----------------------------------------------------

.. automodule:: intranet.apps.announcements.views_LOCAL_1114
:members:
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_LOCAL\_1972 module
-----------------------------------------------------

.. automodule:: intranet.apps.announcements.views_LOCAL_1972
:members:
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_REMOTE\_1087 module
------------------------------------------------------

.. automodule:: intranet.apps.announcements.views_REMOTE_1087
:members:
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_REMOTE\_1114 module
------------------------------------------------------

.. automodule:: intranet.apps.announcements.views_REMOTE_1114
:members:
:undoc-members:
:show-inheritance:

intranet.apps.announcements.views\_REMOTE\_1972 module
------------------------------------------------------

.. automodule:: intranet.apps.announcements.views_REMOTE_1972
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

Expand Down
8 changes: 8 additions & 0 deletions docs/sourcedoc/intranet.apps.bus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ intranet.apps.bus.urls module
:undoc-members:
:show-inheritance:

intranet.apps.bus.utils module
------------------------------

.. automodule:: intranet.apps.bus.utils
:members:
:undoc-members:
:show-inheritance:

intranet.apps.bus.views module
------------------------------

Expand Down
8 changes: 8 additions & 0 deletions docs/sourcedoc/intranet.apps.eighth.management.commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ intranet.apps.eighth.management.commands.absence\_email module
:undoc-members:
:show-inheritance:

intranet.apps.eighth.management.commands.absence\_notify module
---------------------------------------------------------------

.. automodule:: intranet.apps.eighth.management.commands.absence_notify
:members:
:undoc-members:
:show-inheritance:

intranet.apps.eighth.management.commands.delete\_duplicate\_signups module
--------------------------------------------------------------------------

Expand Down
48 changes: 48 additions & 0 deletions docs/sourcedoc/intranet.apps.notifications.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ intranet.apps.notifications package
Submodules
----------

intranet.apps.notifications.admin module
----------------------------------------

.. automodule:: intranet.apps.notifications.admin
:members:
:undoc-members:
:show-inheritance:

intranet.apps.notifications.api module
--------------------------------------

.. automodule:: intranet.apps.notifications.api
:members:
:undoc-members:
:show-inheritance:

intranet.apps.notifications.emails module
-----------------------------------------

Expand All @@ -12,6 +28,14 @@ intranet.apps.notifications.emails module
:undoc-members:
:show-inheritance:

intranet.apps.notifications.forms module
----------------------------------------

.. automodule:: intranet.apps.notifications.forms
:members:
:undoc-members:
:show-inheritance:

intranet.apps.notifications.models module
-----------------------------------------

Expand All @@ -20,6 +44,14 @@ intranet.apps.notifications.models module
:undoc-members:
:show-inheritance:

intranet.apps.notifications.serializers module
----------------------------------------------

.. automodule:: intranet.apps.notifications.serializers
:members:
:undoc-members:
:show-inheritance:

intranet.apps.notifications.tasks module
----------------------------------------

Expand All @@ -28,6 +60,14 @@ intranet.apps.notifications.tasks module
:undoc-members:
:show-inheritance:

intranet.apps.notifications.tests module
----------------------------------------

.. automodule:: intranet.apps.notifications.tests
:members:
:undoc-members:
:show-inheritance:

intranet.apps.notifications.urls module
---------------------------------------

Expand All @@ -36,6 +76,14 @@ intranet.apps.notifications.urls module
:undoc-members:
:show-inheritance:

intranet.apps.notifications.utils module
----------------------------------------

.. automodule:: intranet.apps.notifications.utils
:members:
:undoc-members:
:show-inheritance:

intranet.apps.notifications.views module
----------------------------------------

Expand Down
8 changes: 8 additions & 0 deletions docs/sourcedoc/intranet.apps.polls.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ intranet.apps.polls.models module
:undoc-members:
:show-inheritance:

intranet.apps.polls.notifications module
----------------------------------------

.. automodule:: intranet.apps.polls.notifications
:members:
:undoc-members:
:show-inheritance:

intranet.apps.polls.tests module
--------------------------------

Expand Down
30 changes: 24 additions & 6 deletions intranet/apps/announcements/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ class Meta:
fields = ["title", "author", "content", "groups", "expiration_date", "notify_post", "notify_email_all", "update_added_date", "pinned"]
help_texts = {
"expiration_date": "By default, announcements expire after two weeks. Choose the shortest time necessary.",
"notify_post": "If this box is checked, students who have signed up for notifications will receive an email.",
"notify_post": (
"If this box is checked, students who have signed up for email "
"notifications will receive an email "
"and those who have signed up for push notifications will receive a "
"push notification."
),
"notify_email_all": (
"This will send an email notification to all of the users who can see this post. "
"This option does NOT take users' email notification preferences into account, so please use with care."
Expand All @@ -50,9 +55,12 @@ def __init__(self, user, *args, **kwargs):
else:
self.fields["activity"].queryset = []
self.fields["activity"].required = True
self.fields[
"notify_post"
].help_text = "If this box is checked, students who have subscribed to your club's announcements will receive an email."
self.fields["notify_post"].help_text = (
"If this box is checked, students who have signed up for email "
"notifications will receive an email "
"and those who have signed up for push notifications will receive a "
"push notification."
)

if "instance" in kwargs: # Don't allow changing the activity once the announcement has been created
self.fields["activity"].widget.attrs["disabled"] = True
Expand Down Expand Up @@ -92,7 +100,12 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["expiration_date"].help_text = "By default, announcements expire after two weeks. Choose the shortest time necessary."

self.fields["notify_post_resend"].help_text = "If this box is checked, students who have signed up for notifications will receive an email."
self.fields["notify_post_resend"].help_text = (
"If this box is checked, students who have signed up for email "
"notifications will receive an email "
"and those who have signed up for push notifications will "
"receive a push notification."
)

self.fields["notify_email_all_resend"].help_text = (
"This will resend an email notification to all of the users who can see this post. This option "
Expand Down Expand Up @@ -153,7 +166,12 @@ class AnnouncementAdminForm(forms.Form):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["notify_post"].help_text = "If this box is checked, students who have signed up for notifications will receive an email."
self.fields["notify_post"].help_text = (
"If this box is checked, students who have signed up for email "
"notifications will receive an email "
"and those who have signed up for push notifications will receive a "
"push notification."
)
self.fields["notify_email_all"].help_text = (
"This will send an email notification to all of the users who can see this post. This option "
"does NOT take users' email notification preferences into account, so please use with care."
Expand Down
Loading
Loading