From 2af1f459b51668d0dc9d3f4b1f502f7db7e5943b Mon Sep 17 00:00:00 2001 From: Graham Herceg Date: Thu, 12 Dec 2024 16:23:37 -0500 Subject: [PATCH] Allow if device_id is none Admins can trigger restores from HQ without a device_id --- corehq/apps/ota/tests/test_utils.py | 6 ++++++ corehq/apps/ota/utils.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/corehq/apps/ota/tests/test_utils.py b/corehq/apps/ota/tests/test_utils.py index b515f44903f4..c613e55c3ccc 100644 --- a/corehq/apps/ota/tests/test_utils.py +++ b/corehq/apps/ota/tests/test_utils.py @@ -511,6 +511,12 @@ def test_allowed_for_different_user(self): with patch('corehq.apps.ota.utils.DEVICES_PER_USER', 1): self.assertTrue(can_login_on_device('def456', 'device-id')) + def test_device_id_is_none_is_allowed(self): + self._create_synclog(self.domain, 'abc123', 'device-id', date=self.within_past_day) + + with patch('corehq.apps.ota.utils.DEVICES_PER_USER', 1): + self.assertTrue(can_login_on_device('abc123', 'device-id')) + def _create_synclog(self, domain, user_id, device_id, **kwargs): SyncLogSQL.objects.create( domain=domain, diff --git a/corehq/apps/ota/utils.py b/corehq/apps/ota/utils.py index be74a065f5c3..ed0bbdab975f 100644 --- a/corehq/apps/ota/utils.py +++ b/corehq/apps/ota/utils.py @@ -227,7 +227,7 @@ def _inner(request, domain, *args, **kwargs): def can_login_on_device(user_id, device_id): - if device_id.startswith("WebAppsLogin"): + if not device_id or device_id.startswith("WebAppsLogin"): return True end_time = datetime.now()