mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
Fix bug where we hard code realm for PushDeviceToken.
This had no test coverage, which is part of the reason it went undetected, plus many instances probably only have one realm with realm_id=1.
This commit is contained in:
@@ -1670,7 +1670,7 @@ class UserPresence(models.Model):
|
||||
)
|
||||
|
||||
mobile_user_ids = [row['user'] for row in PushDeviceToken.objects.filter(
|
||||
user__realm_id=1,
|
||||
user__realm_id=realm_id,
|
||||
user__is_active=True,
|
||||
user__is_bot=False,
|
||||
).distinct("user").values("user")]
|
||||
|
||||
@@ -19,6 +19,7 @@ from zerver.lib.timestamp import datetime_to_timestamp
|
||||
from zerver.models import (
|
||||
email_to_domain,
|
||||
Client,
|
||||
PushDeviceToken,
|
||||
UserActivity,
|
||||
UserProfile,
|
||||
UserPresence,
|
||||
@@ -92,6 +93,36 @@ class UserPresenceModelTests(ZulipTestCase):
|
||||
presence_dct = UserPresence.get_status_dict_by_realm(user_profile.realm_id)
|
||||
self.assertEqual(len(presence_dct), 0)
|
||||
|
||||
def test_push_tokens(self):
|
||||
# type: () -> None
|
||||
UserPresence.objects.all().delete()
|
||||
|
||||
user_profile = self.example_user('hamlet')
|
||||
email = user_profile.email
|
||||
|
||||
self.login(email)
|
||||
result = self.client_post("/json/users/me/presence", {'status': 'active'})
|
||||
self.assert_json_success(result)
|
||||
|
||||
def pushable():
|
||||
# type: () -> bool
|
||||
presence_dct = UserPresence.get_status_dict_by_realm(user_profile.realm_id)
|
||||
self.assertEqual(len(presence_dct), 1)
|
||||
return presence_dct[email]['website']['pushable']
|
||||
|
||||
self.assertFalse(pushable())
|
||||
|
||||
user_profile.enable_offline_push_notifications = True
|
||||
user_profile.save()
|
||||
|
||||
self.assertFalse(pushable())
|
||||
|
||||
PushDeviceToken.objects.create(
|
||||
user=user_profile,
|
||||
kind=PushDeviceToken.APNS
|
||||
)
|
||||
self.assertTrue(pushable())
|
||||
|
||||
class UserPresenceTests(ZulipTestCase):
|
||||
def test_invalid_presence(self):
|
||||
# type: () -> None
|
||||
|
||||
Reference in New Issue
Block a user