diff --git a/README.md b/README.md index f7cae21f..6e3ed680 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,8 @@ requests, code review feedback, and also pull requests. ## Supported Python Versions -We currently support Python 3.7+. However, Python 3.7 support is deprecated, -and developers are strongly advised to use Python 3.8 or higher. Firebase +We currently support Python 3.7+. However, Python 3.7 and Python 3.8 support is deprecated, +and developers are strongly advised to use Python 3.9 or higher. Firebase Admin Python SDK is also tested on PyPy and [Google App Engine](https://cloud.google.com/appengine/) environments. diff --git a/firebase_admin/__about__.py b/firebase_admin/__about__.py index 2c606611..c822fb37 100644 --- a/firebase_admin/__about__.py +++ b/firebase_admin/__about__.py @@ -14,7 +14,7 @@ """About information (version, etc) for Firebase Admin SDK.""" -__version__ = '6.7.0' +__version__ = '6.8.0' __title__ = 'firebase_admin' __author__ = 'Firebase' __license__ = 'Apache License 2.0' diff --git a/firebase_admin/_messaging_encoder.py b/firebase_admin/_messaging_encoder.py index 85072b59..d7f23328 100644 --- a/firebase_admin/_messaging_encoder.py +++ b/firebase_admin/_messaging_encoder.py @@ -319,7 +319,9 @@ def encode_android_notification(cls, notification): 'visibility': _Validators.check_string( 'AndroidNotification.visibility', notification.visibility, non_empty=True), 'notification_count': _Validators.check_number( - 'AndroidNotification.notification_count', notification.notification_count) + 'AndroidNotification.notification_count', notification.notification_count), + 'proxy': _Validators.check_string( + 'AndroidNotification.proxy', notification.proxy, non_empty=True) } result = cls.remove_null_values(result) color = result.get('color') @@ -363,6 +365,13 @@ def encode_android_notification(cls, notification): 'AndroidNotification.vibrate_timings_millis', msec) vibrate_timing_strings.append(formated_string) result['vibrate_timings'] = vibrate_timing_strings + + proxy = result.get('proxy') + if proxy: + if proxy not in ('allow', 'deny', 'if_priority_lowered'): + raise ValueError( + 'AndroidNotification.proxy must be "allow", "deny" or "if_priority_lowered".') + result['proxy'] = proxy.upper() return result @classmethod diff --git a/firebase_admin/_messaging_utils.py b/firebase_admin/_messaging_utils.py index 29b8276b..ae1f5cc5 100644 --- a/firebase_admin/_messaging_utils.py +++ b/firebase_admin/_messaging_utils.py @@ -137,7 +137,8 @@ class AndroidNotification: If ``default_light_settings`` is set to ``True`` and ``light_settings`` is also set, the user-specified ``light_settings`` is used instead of the default value. visibility: Sets the visibility of the notification. Must be either ``private``, ``public``, - or ``secret``. If unspecified, default to ``private``. + or ``secret``. If unspecified, it remains undefined in the Admin SDK, and defers to + the FCM backend's default mapping. notification_count: Sets the number of items this notification represents. May be displayed as a badge count for Launchers that support badging. See ``NotificationBadge`` https://developer.android.com/training/notify-user/badges. For example, this might be @@ -145,6 +146,9 @@ class AndroidNotification: want the count here to represent the number of total new messages. If zero or unspecified, systems that support badging use the default, which is to increment a number displayed on the long-press menu each time a new notification arrives. + proxy: Sets if the notification may be proxied. Must be one of ``allow``, ``deny``, or + ``if_priority_lowered``. If unspecified, it remains undefined in the Admin SDK, and + defers to the FCM backend's default mapping. """ @@ -154,7 +158,8 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag title_loc_args=None, channel_id=None, image=None, ticker=None, sticky=None, event_timestamp=None, local_only=None, priority=None, vibrate_timings_millis=None, default_vibrate_timings=None, default_sound=None, light_settings=None, - default_light_settings=None, visibility=None, notification_count=None): + default_light_settings=None, visibility=None, notification_count=None, + proxy=None): self.title = title self.body = body self.icon = icon @@ -180,6 +185,7 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag self.default_light_settings = default_light_settings self.visibility = visibility self.notification_count = notification_count + self.proxy = proxy class LightSettings: diff --git a/integration/test_messaging.py b/integration/test_messaging.py index 50b4ae3a..4c1d7d0d 100644 --- a/integration/test_messaging.py +++ b/integration/test_messaging.py @@ -55,7 +55,8 @@ def test_send(): light_off_duration_millis=200, light_on_duration_millis=300 ), - notification_count=1 + notification_count=1, + proxy='if_priority_lowered', ) ), apns=messaging.APNSConfig(payload=messaging.APNSPayload( diff --git a/tests/test_messaging.py b/tests/test_messaging.py index edb36f53..b7b5c69b 100644 --- a/tests/test_messaging.py +++ b/tests/test_messaging.py @@ -535,6 +535,20 @@ def test_invalid_visibility(self, visibility): expected = 'AndroidNotification.visibility must be a non-empty string.' assert str(excinfo.value) == expected + @pytest.mark.parametrize('proxy', NON_STRING_ARGS + ['foo']) + def test_invalid_proxy(self, proxy): + notification = messaging.AndroidNotification(proxy=proxy) + excinfo = self._check_notification(notification) + if isinstance(proxy, str): + if not proxy: + expected = 'AndroidNotification.proxy must be a non-empty string.' + else: + expected = ('AndroidNotification.proxy must be "allow", "deny" or' + ' "if_priority_lowered".') + else: + expected = 'AndroidNotification.proxy must be a non-empty string.' + assert str(excinfo.value) == expected + @pytest.mark.parametrize('vibrate_timings', ['', 1, True, 'msec', ['500', 500], [0, 'abc']]) def test_invalid_vibrate_timings_millis(self, vibrate_timings): notification = messaging.AndroidNotification(vibrate_timings_millis=vibrate_timings) @@ -580,6 +594,7 @@ def test_android_notification(self): light_off_duration_millis=300, ), default_light_settings=False, visibility='public', notification_count=1, + proxy='if_priority_lowered', ) ) ) @@ -620,6 +635,7 @@ def test_android_notification(self): 'default_light_settings': False, 'visibility': 'PUBLIC', 'notification_count': 1, + 'proxy': 'IF_PRIORITY_LOWERED' }, }, }