2013-10-17 16:33:04 +02:00
|
|
|
from django.db import models
|
2016-07-30 00:33:29 +02:00
|
|
|
from django.db.models import Manager
|
2016-10-27 23:55:31 +02:00
|
|
|
from typing import Dict, Optional, Text
|
2016-07-30 00:33:29 +02:00
|
|
|
|
2013-10-17 16:33:04 +02:00
|
|
|
import zerver.models
|
2016-10-27 23:55:31 +02:00
|
|
|
import datetime
|
2013-10-17 16:33:04 +02:00
|
|
|
|
2016-10-27 23:55:31 +02:00
|
|
|
def get_remote_server_by_uuid(uuid):
|
|
|
|
# type: (Text) -> RemoteZulipServer
|
|
|
|
return RemoteZulipServer.objects.get(uuid=uuid)
|
|
|
|
|
|
|
|
class RemoteZulipServer(models.Model):
|
|
|
|
uuid = models.CharField(max_length=36, unique=True) # type: Text
|
|
|
|
api_key = models.CharField(max_length=64) # type: Text
|
|
|
|
|
|
|
|
hostname = models.CharField(max_length=128, unique=True) # type: Text
|
|
|
|
contact_email = models.EmailField(blank=True, null=False) # type: Text
|
|
|
|
last_updated = models.DateTimeField('last updated') # type: datetime.datetime
|
|
|
|
|
|
|
|
# Variant of PushDeviceToken for a remote server.
|
|
|
|
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
|
2013-10-17 16:33:04 +02:00
|
|
|
|
|
|
|
class Deployment(models.Model):
|
2016-07-30 00:33:29 +02:00
|
|
|
realms = models.ManyToManyField(zerver.models.Realm,
|
|
|
|
related_name="_deployments") # type: Manager
|
|
|
|
is_active = models.BooleanField(default=True) # type: bool
|
2013-10-17 16:33:04 +02:00
|
|
|
|
|
|
|
# TODO: This should really become the public portion of a keypair, and
|
|
|
|
# it should be settable only with an initial bearer "activation key"
|
2016-12-08 05:06:51 +01:00
|
|
|
api_key = models.CharField(max_length=32, null=True) # type: Text
|
2013-10-23 23:39:34 +02:00
|
|
|
|
2016-12-08 05:06:51 +01:00
|
|
|
base_api_url = models.CharField(max_length=128) # type: Text
|
|
|
|
base_site_url = models.CharField(max_length=128) # type: Text
|
2013-10-24 00:27:52 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def endpoints(self):
|
2016-12-08 05:06:51 +01:00
|
|
|
# type: () -> Dict[str, Text]
|
2013-10-24 00:27:52 +02:00
|
|
|
return {'base_api_url': self.base_api_url, 'base_site_url': self.base_site_url}
|
2013-11-13 17:16:31 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-12-08 05:06:51 +01:00
|
|
|
# type: () -> Text
|
2016-07-30 00:33:29 +02:00
|
|
|
|
2013-11-13 17:16:31 +01:00
|
|
|
# TODO: This only does the right thing for prod because prod authenticates to
|
|
|
|
# staging with the zulip.com deployment key, while staging is technically the
|
|
|
|
# deployment for the zulip.com realm.
|
2016-10-27 23:55:31 +02:00
|
|
|
# This also doesn't necessarily handle other multi-realm deployments correctly
|
2013-11-13 17:16:31 +01:00
|
|
|
return self.realms.order_by('pk')[0].domain
|