zilencer: Fix uniqueness rules for RemotePushDeviceToken.

Since a user could use the same installation of the Zulip mobile app
with multiple Zulip servers, correct behavior is to allow reusing the
same token with multiple Zulip servers in the RemotePushDeviceToken
model.
This commit is contained in:
Tim Abbott 2017-10-18 21:21:27 -07:00
parent c61b6d06e5
commit 735b49e505
3 changed files with 35 additions and 2 deletions

View File

@ -821,7 +821,6 @@ class AbstractPushDeviceToken(models.Model):
# sent to us from each device:
# - APNS token if kind == APNS
# - GCM registration id if kind == GCM
token = models.CharField(max_length=4096, unique=True) # type: bytes
last_updated = models.DateTimeField(auto_now=True) # type: datetime.datetime
# [optional] Contains the app id of the device if it is an iOS device
@ -833,6 +832,7 @@ class AbstractPushDeviceToken(models.Model):
class PushDeviceToken(AbstractPushDeviceToken):
# The user who's device this is
user = models.ForeignKey(UserProfile, db_index=True, on_delete=CASCADE) # type: UserProfile
token = models.CharField(max_length=4096, unique=True) # type: bytes
def generate_email_token_for_stream():
# type: () -> str

View File

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-10-19 04:23
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('zilencer', '0004_remove_deployment_model'),
]
operations = [
migrations.AlterField(
model_name='remotepushdevicetoken',
name='token',
field=models.CharField(db_index=True, max_length=4096),
),
migrations.AlterField(
model_name='remotepushdevicetoken',
name='user_id',
field=models.BigIntegerField(db_index=True),
),
migrations.AlterUniqueTogether(
name='remotepushdevicetoken',
unique_together=set([('server', 'token')]),
),
]

View File

@ -21,4 +21,8 @@ class RemoteZulipServer(models.Model):
class RemotePushDeviceToken(zerver.models.AbstractPushDeviceToken):
server = models.ForeignKey(RemoteZulipServer) # type: RemoteZulipServer
# The user id on the remote server for this device device this is
user_id = models.BigIntegerField() # type: int
user_id = models.BigIntegerField(db_index=True) # type: int
token = models.CharField(max_length=4096, db_index=True) # type: bytes
class Meta(object):
unique_together = ("server", "token")