mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 17:36:27 +00:00
push_notification: Delete obsolete DBX_IOS_APP_ID code.
I'm not sure that this was ever actually used, but it's definitely just clutter for Zulip today.
This commit is contained in:
@@ -61,10 +61,6 @@ redis_client = get_redis_client()
|
|||||||
# for each request
|
# for each request
|
||||||
connection = None
|
connection = None
|
||||||
|
|
||||||
# We maintain an additional APNS connection for pushing to Zulip apps that have been signed
|
|
||||||
# by the Dropbox certs (and have an app id of com.dropbox.zulip)
|
|
||||||
dbx_connection = None
|
|
||||||
|
|
||||||
# `APNS_SANDBOX` should be a bool
|
# `APNS_SANDBOX` should be a bool
|
||||||
assert isinstance(settings.APNS_SANDBOX, bool)
|
assert isinstance(settings.APNS_SANDBOX, bool)
|
||||||
|
|
||||||
@@ -147,10 +143,6 @@ if settings.APNS_CERT_FILE is not None and os.path.exists(settings.APNS_CERT_FIL
|
|||||||
connection = get_connection(settings.APNS_CERT_FILE,
|
connection = get_connection(settings.APNS_CERT_FILE,
|
||||||
settings.APNS_KEY_FILE)
|
settings.APNS_KEY_FILE)
|
||||||
|
|
||||||
if settings.DBX_APNS_CERT_FILE is not None and os.path.exists(settings.DBX_APNS_CERT_FILE): # nocoverage
|
|
||||||
dbx_connection = get_connection(settings.DBX_APNS_CERT_FILE,
|
|
||||||
settings.DBX_APNS_KEY_FILE)
|
|
||||||
|
|
||||||
def num_push_devices_for_user(user_profile, kind = None):
|
def num_push_devices_for_user(user_profile, kind = None):
|
||||||
# type: (UserProfile, Optional[int]) -> PushDeviceToken
|
# type: (UserProfile, Optional[int]) -> PushDeviceToken
|
||||||
if kind is None:
|
if kind is None:
|
||||||
@@ -169,7 +161,7 @@ def hex_to_b64(data):
|
|||||||
|
|
||||||
def _do_push_to_apns_service(user_id, message, apns_connection):
|
def _do_push_to_apns_service(user_id, message, apns_connection):
|
||||||
# type: (int, APNsMessage, APNs) -> None
|
# type: (int, APNsMessage, APNs) -> None
|
||||||
if not apns_connection:
|
if not apns_connection: # nocoverage
|
||||||
logging.info("Not delivering APNS message %s to user %s due to missing connection" % (message, user_id))
|
logging.info("Not delivering APNS message %s to user %s due to missing connection" % (message, user_id))
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -188,7 +180,7 @@ def send_apple_push_notification_to_user(user, alert, **extra_data):
|
|||||||
@statsd_increment("apple_push_notification")
|
@statsd_increment("apple_push_notification")
|
||||||
def send_apple_push_notification(user_id, devices, **extra_data):
|
def send_apple_push_notification(user_id, devices, **extra_data):
|
||||||
# type: (int, List[DeviceToken], **Any) -> None
|
# type: (int, List[DeviceToken], **Any) -> None
|
||||||
if not connection and not dbx_connection:
|
if not connection:
|
||||||
logging.warning("Attempting to send push notification, but no connection was found. "
|
logging.warning("Attempting to send push notification, but no connection was found. "
|
||||||
"This may be because we could not find the APNS Certificate file.")
|
"This may be because we could not find the APNS Certificate file.")
|
||||||
return
|
return
|
||||||
@@ -197,11 +189,7 @@ def send_apple_push_notification(user_id, devices, **extra_data):
|
|||||||
tokens = [(b64_to_hex(device.token), device.ios_app_id, device.token)
|
tokens = [(b64_to_hex(device.token), device.ios_app_id, device.token)
|
||||||
for device in devices]
|
for device in devices]
|
||||||
|
|
||||||
for conn, app_ids in [
|
valid_devices = [device for device in tokens if device[1] in [settings.ZULIP_IOS_APP_ID, None]]
|
||||||
(connection, [settings.ZULIP_IOS_APP_ID, None]),
|
|
||||||
(dbx_connection, [settings.DBX_IOS_APP_ID])]:
|
|
||||||
|
|
||||||
valid_devices = [device for device in tokens if device[1] in app_ids]
|
|
||||||
valid_tokens = [device[0] for device in valid_devices]
|
valid_tokens = [device[0] for device in valid_devices]
|
||||||
if valid_tokens:
|
if valid_tokens:
|
||||||
logging.info("APNS: Sending apple push notification "
|
logging.info("APNS: Sending apple push notification "
|
||||||
@@ -209,10 +197,10 @@ def send_apple_push_notification(user_id, devices, **extra_data):
|
|||||||
zulip_message = APNsMessage(user_id, valid_tokens,
|
zulip_message = APNsMessage(user_id, valid_tokens,
|
||||||
alert=extra_data['zulip']['alert'],
|
alert=extra_data['zulip']['alert'],
|
||||||
**extra_data)
|
**extra_data)
|
||||||
_do_push_to_apns_service(user_id, zulip_message, conn)
|
_do_push_to_apns_service(user_id, zulip_message, connection)
|
||||||
else:
|
else: # nocoverage
|
||||||
logging.warn("APNS: Not sending notification because "
|
logging.warn("APNS: Not sending notification because "
|
||||||
"tokens didn't match devices: %s" % (app_ids,))
|
"tokens didn't match devices: %s/%s" % (tokens, settings.ZULIP_IOS_APP_ID,))
|
||||||
|
|
||||||
# NOTE: This is used by the check_apns_tokens manage.py command. Do not call it otherwise, as the
|
# NOTE: This is used by the check_apns_tokens manage.py command. Do not call it otherwise, as the
|
||||||
# feedback() call can take up to 15s
|
# feedback() call can take up to 15s
|
||||||
|
|||||||
@@ -233,7 +233,6 @@ class PushNotificationTest(BouncerTestCase):
|
|||||||
self.user_profile = self.example_user('hamlet')
|
self.user_profile = self.example_user('hamlet')
|
||||||
apn.connection = apn.get_connection('fake-cert', 'fake-key')
|
apn.connection = apn.get_connection('fake-cert', 'fake-key')
|
||||||
self.redis_client = apn.redis_client = MockRedis() # type: ignore
|
self.redis_client = apn.redis_client = MockRedis() # type: ignore
|
||||||
apn.dbx_connection = apn.get_connection('fake-cert', 'fake-key')
|
|
||||||
self.tokens = [u'aaaa', u'bbbb']
|
self.tokens = [u'aaaa', u'bbbb']
|
||||||
for token in self.tokens:
|
for token in self.tokens:
|
||||||
PushDeviceToken.objects.create(
|
PushDeviceToken.objects.create(
|
||||||
@@ -306,8 +305,7 @@ class HandlePushNotificationTest(PushNotificationTest):
|
|||||||
mock.patch('zerver.lib.push_notifications.requests.request',
|
mock.patch('zerver.lib.push_notifications.requests.request',
|
||||||
side_effect=self.bounce_request), \
|
side_effect=self.bounce_request), \
|
||||||
mock.patch('zerver.lib.push_notifications._do_push_to_apns_service'), \
|
mock.patch('zerver.lib.push_notifications._do_push_to_apns_service'), \
|
||||||
mock.patch('logging.info') as mock_info, \
|
mock.patch('logging.info') as mock_info:
|
||||||
mock.patch('logging.warn') as mock_warn:
|
|
||||||
apn.handle_push_notification(self.user_profile.id, missed_message)
|
apn.handle_push_notification(self.user_profile.id, missed_message)
|
||||||
devices = [
|
devices = [
|
||||||
(apn.b64_to_hex(device.token), device.ios_app_id, device.token)
|
(apn.b64_to_hex(device.token), device.ios_app_id, device.token)
|
||||||
@@ -315,10 +313,6 @@ class HandlePushNotificationTest(PushNotificationTest):
|
|||||||
]
|
]
|
||||||
mock_info.assert_called_with("APNS: Sending apple push "
|
mock_info.assert_called_with("APNS: Sending apple push "
|
||||||
"notification to devices: %s" % (devices,))
|
"notification to devices: %s" % (devices,))
|
||||||
mock_warn.assert_called_with("APNS: Not sending "
|
|
||||||
"notification because tokens "
|
|
||||||
"didn't match devices: "
|
|
||||||
"['com.dropbox.Zulip']")
|
|
||||||
|
|
||||||
def test_disabled_notifications(self):
|
def test_disabled_notifications(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
@@ -723,19 +717,11 @@ class SendNotificationTest(PushNotificationTest):
|
|||||||
@mock.patch('logging.warn')
|
@mock.patch('logging.warn')
|
||||||
@mock.patch('logging.info')
|
@mock.patch('logging.info')
|
||||||
@mock.patch('apns.GatewayConnection.send_notification_multiple')
|
@mock.patch('apns.GatewayConnection.send_notification_multiple')
|
||||||
def test_connection_single_none(self, mock_push, mock_info, mock_warn):
|
def test_connection_none(self, mock_push, mock_info, mock_warn):
|
||||||
# type: (mock.MagicMock, mock.MagicMock, mock.MagicMock) -> None
|
# type: (mock.MagicMock, mock.MagicMock, mock.MagicMock) -> None
|
||||||
apn.connection = None
|
apn.connection = None
|
||||||
apn.send_apple_push_notification_to_user(self.user_profile, "test alert")
|
apn.send_apple_push_notification_to_user(self.user_profile, "test alert")
|
||||||
|
|
||||||
@mock.patch('logging.error')
|
|
||||||
@mock.patch('apns.GatewayConnection.send_notification_multiple')
|
|
||||||
def test_connection_both_none(self, mock_push, mock_error):
|
|
||||||
# type: (mock.MagicMock, mock.MagicMock) -> None
|
|
||||||
apn.connection = None
|
|
||||||
apn.dbx_connection = None
|
|
||||||
apn.send_apple_push_notification_to_user(self.user_profile, "test alert")
|
|
||||||
|
|
||||||
class APNsFeedbackTest(PushNotificationTest):
|
class APNsFeedbackTest(PushNotificationTest):
|
||||||
@mock.patch('logging.info')
|
@mock.patch('logging.info')
|
||||||
@mock.patch('apns.FeedbackConnection.items')
|
@mock.patch('apns.FeedbackConnection.items')
|
||||||
|
|||||||
@@ -1204,7 +1204,6 @@ POLL_TIMEOUT = 90 * 1000
|
|||||||
|
|
||||||
# iOS App IDs
|
# iOS App IDs
|
||||||
ZULIP_IOS_APP_ID = 'com.zulip.Zulip'
|
ZULIP_IOS_APP_ID = 'com.zulip.Zulip'
|
||||||
DBX_IOS_APP_ID = 'com.dropbox.Zulip'
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
# SSO AND LDAP SETTINGS
|
# SSO AND LDAP SETTINGS
|
||||||
|
|||||||
Reference in New Issue
Block a user