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

Remove firebase-admin dependency #35798

Merged
merged 3 commits into from
Feb 19, 2025
Merged
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: 2 additions & 5 deletions corehq/apps/ota/tests/test_heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class HeartbeatTests(TestCase):
def setUpClass(cls):
super(HeartbeatTests, cls).setUpClass()
cls.domain_obj = create_domain(uuid4().hex)
cls.addClassCleanup(cls.domain_obj.delete)
cls.user = CommCareUser.create(cls.domain_obj.name, 'user1', '123', None, None)
cls.addClassCleanup(cls.user.delete, None, None)
cls.app, cls.build = cls._create_app_and_build()
cls.url = reverse('phone_heartbeat', args=[cls.domain_obj.name, cls.build.get_id])

Expand All @@ -36,11 +38,6 @@ def _create_app_and_build(cls):
build.save(increment_version=False)
return app, build

@classmethod
def tearDownClass(cls):
cls.domain_obj.delete()
super(HeartbeatTests, cls).tearDownClass()

def _auth_headers(self, user):
return {
'HTTP_AUTHORIZATION': 'Basic ' + base64.b64encode(
Expand Down
10 changes: 0 additions & 10 deletions corehq/apps/sms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,11 +1110,6 @@ class MessagingEvent(models.Model, MessagingStatusMixin):
ERROR_EMAIL_BOUNCED = 'EMAIL_BOUNCED'
ERROR_EMAIL_GATEWAY = 'EMAIL_GATEWAY_ERROR'
ERROR_NO_FCM_TOKENS = 'NO_FCM_TOKENS'
ERROR_FCM_NOT_AVAILABLE = 'FCM_NOT_AVAILABLE'
ERROR_FCM_UNSUPPORTED_RECIPIENT = 'FCM_UNSUPPORTED_RECIPIENT'
ERROR_FCM_NO_ACTION = "FCM_NO_ACTION"
ERROR_FCM_NOTIFICATION_FAILURE = "FCM_NOTIFICATION_FAILURE"
ERROR_FCM_DOMAIN_NOT_ENABLED = 'FCM_DOMAIN_NOT_ENABLED'
FILTER_MISMATCH = 'FILTER_MISMATCH'

ERROR_MESSAGES = {
Expand Down Expand Up @@ -1172,11 +1167,6 @@ class MessagingEvent(models.Model, MessagingStatusMixin):
ERROR_EMAIL_BOUNCED: gettext_noop("Email Bounced"),
ERROR_EMAIL_GATEWAY: gettext_noop("Email Gateway Error"),
ERROR_NO_FCM_TOKENS: gettext_noop("No FCM tokens found for recipient."),
ERROR_FCM_NOT_AVAILABLE: gettext_noop("FCM not available on this environment."),
ERROR_FCM_UNSUPPORTED_RECIPIENT: gettext_noop("FCM is supported for Mobile Workers only."),
ERROR_FCM_NO_ACTION: gettext_noop("No action selected for the FCM Data message type."),
ERROR_FCM_NOTIFICATION_FAILURE: gettext_noop("Failure while sending FCM notifications to the devices."),
ERROR_FCM_DOMAIN_NOT_ENABLED: gettext_noop("Domain is not enabled for FCM Push Notifications"),
FILTER_MISMATCH: gettext_noop("Recipient did not match filters:")
}

Expand Down
73 changes: 0 additions & 73 deletions corehq/messaging/fcm/utils.py

This file was deleted.

63 changes: 3 additions & 60 deletions corehq/messaging/scheduling/models/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import jsonfield as old_jsonfield

from dimagi.utils.logging import notify_error
from dimagi.utils.modules import to_function

from corehq import toggles
Expand All @@ -25,14 +26,12 @@
PhoneNumber,
)
from corehq.apps.smsforms.tasks import send_first_message
from corehq.apps.users.models import CommCareUser
from corehq.blobs import CODES, get_blob_db
from corehq.blobs.exceptions import NotFound
from corehq.blobs.models import BlobMeta
from corehq.blobs.util import random_url_id
from corehq.form_processor.utils import is_commcarecase
from corehq.messaging.fcm.exceptions import FCMTokenValidationException
from corehq.messaging.fcm.utils import FCMUtil
from corehq.messaging.scheduling.exceptions import EmailValidationException
from corehq.messaging.scheduling.models.abstract import Content, SurveyContent
from corehq.sql_db.util import get_db_aliases_for_partitioned_query
Expand Down Expand Up @@ -482,69 +481,13 @@ def build_fcm_data_field(self, recipient):
return data

def send(self, recipient, logged_event, phone_entry=None):
domain_obj = Domain.get_by_name(logged_event.domain)

logged_subevent = logged_event.create_subevent_from_contact_and_content(
recipient,
self,
case_id=self.case.case_id if self.case else None,
)
subject = message = data = None

if not settings.FCM_CREDS:
logged_subevent.error(MessagingEvent.ERROR_FCM_NOT_AVAILABLE)
return

if not toggles.FCM_NOTIFICATION.enabled(logged_event.domain):
logged_subevent.error(MessagingEvent.ERROR_FCM_DOMAIN_NOT_ENABLED)
return

if not isinstance(recipient, CommCareUser):
logged_subevent.error(MessagingEvent.ERROR_FCM_UNSUPPORTED_RECIPIENT)
return

if self.message_type == self.MESSAGE_TYPE_NOTIFICATION:
if not (self.subject or self.message):
logged_subevent.error(MessagingEvent.ERROR_NO_MESSAGE)
return

recipient_language_code = recipient.get_language_code()
subject = self.get_translation_from_message_dict(
domain_obj,
self.subject,
recipient_language_code
)

message = self.get_translation_from_message_dict(
domain_obj,
self.message,
recipient_language_code
)

try:
subject, message = self.render_subject_and_message(subject, message, recipient)
except Exception:
logged_subevent.error(MessagingEvent.ERROR_CANNOT_RENDER_MESSAGE)
return
else:
if not self.action:
logged_subevent.error(MessagingEvent.ERROR_FCM_NO_ACTION)
return
data = self.build_fcm_data_field(recipient)

try:
devices_fcm_tokens = self.get_recipient_devices_fcm_tokens(recipient)
except FCMTokenValidationException as e:
logged_subevent.error(e.error_type, additional_error_text=e.additional_text)
return

result = FCMUtil().send_to_multiple_devices(registration_tokens=devices_fcm_tokens, title=subject,
body=message, data=data)
if result.failure_count == len(devices_fcm_tokens):
logged_subevent.error(MessagingEvent.ERROR_FCM_NOTIFICATION_FAILURE)
return

logged_subevent.completed()
logged_subevent.error("FCM pre-release feature has been removed. Please contact support.")
notify_error("FCM pre-release feature has been removed and is not expected to be in use.")

def get_recipient_devices_fcm_tokens(self, recipient):
devices_fcm_tokens = recipient.get_devices_fcm_tokens()
Expand Down
3 changes: 1 addition & 2 deletions corehq/toggles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,12 +2639,11 @@ def _handle_geospatial_es_index(domain, is_enabled):
tag=TAG_INTERNAL,
namespaces=[NAMESPACE_DOMAIN],
description='More details to come',

)

FCM_NOTIFICATION = StaticToggle(
'fcm_notification',
'Allows access to FCM Push Notifications',
'FCM Push Notifications - no longer functional',
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @ajeety4

Can you confirm that this would discontinue the feature itself then, FCM notifications?

Copy link
Contributor

Choose a reason for hiding this comment

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

The code changes in this PR should simply log an error in case a fcm push notification are attempted via the conditional alerts. I believe follow up work will be require to entirely remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ajeety4 Can you help with a ticket for the same? also, no projects are using this?

fyi @shubham1g5 if there is anything to be removed from app side?

Copy link
Contributor

Choose a reason for hiding this comment

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

Correction, the code has been asked to kept around for future use.

Offline chat reference

TAG_CUSTOM,
namespaces=[NAMESPACE_DOMAIN],
description='Push Notification option will be available in content for '
Expand Down
1 change: 0 additions & 1 deletion requirements/base-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ elasticsearch5>=5.0.0,<6.0.0
elasticsearch6>=6.0.0,<7.0.0
ethiopian-date-converter
eulxml
firebase-admin # India Division - used for FCM Push Notifications
gevent
greenlet
gunicorn
Expand Down
Loading
Loading