Skip to content

Commit

Permalink
Add Notifications path (#332)
Browse files Browse the repository at this point in the history
* Paths_Fixed
  • Loading branch information
zachHarpaz authored Nov 19, 2024
1 parent 00587a3 commit 73dc150
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
2 changes: 2 additions & 0 deletions backend/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ def create_or_update_user_profile(sender, instance, created, **kwargs):
object exists for that User, it will create one
"""
Profile.objects.get_or_create(user=instance)
if courses_service := NotificationService.objects.filter(name="COURSES").first():
courses_service.enabled_users.add(instance)
13 changes: 4 additions & 9 deletions backend/user/notifications.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import collections
import os
import sys
from abc import ABC, abstractmethod

Expand Down Expand Up @@ -62,11 +61,8 @@ def send_one_notification(self, token, payload):
class AndroidNotificationWrapper(NotificationWrapper):
def __init__(self):
try:
server_key = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
"penn-mobile-android-firebase-adminsdk-u9rki-c83fb20713.json",
)
cred = credentials.Certificate(server_key)
auth_key_path = "/app/secrets/notifications/android/fcm.json"
cred = credentials.Certificate(auth_key_path)
firebase_admin.initialize_app(cred)
except Exception as e:
print(f"Notifications Error: Failed to initialize Firebase client: {e}")
Expand All @@ -90,9 +86,8 @@ def send_one_notification(self, token, payload):
class IOSNotificationWrapper(NotificationWrapper):
@staticmethod
def get_client(is_dev):
auth_key_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
f"apns-{'dev' if is_dev else 'prod'}.pem",
auth_key_path = (
f"/app/secrets/notifications/ios{'/dev/apns-dev' if is_dev else '/prod/apns-prod'}.pem"
)
return APNsClient(credentials=auth_key_path, use_sandbox=is_dev)

Expand Down
Empty file removed backend/wrapped/tests.py
Empty file.

0 comments on commit 73dc150

Please sign in to comment.