From 66a3f514d4fd1925990658391abd72d15be3e799 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 11 Oct 2017 23:26:54 -0700 Subject: [PATCH] zilencer: Remove long-obsolete Deployment model. This was a precursor to RemoteZulipServer, which is no longer used for anything, and was cluttering the codebase. --- zerver/management/commands/export.py | 2 +- zerver/tests/test_messages.py | 20 ++------------ zerver/tests/test_signup.py | 1 - zerver/tests/test_upload.py | 12 --------- .../0004_remove_deployment_model.py | 22 +++++++++++++++ zilencer/models.py | 27 ------------------- zilencer/urls.py | 2 -- zilencer/views.py | 8 +----- 8 files changed, 26 insertions(+), 68 deletions(-) create mode 100644 zilencer/migrations/0004_remove_deployment_model.py diff --git a/zerver/management/commands/export.py b/zerver/management/commands/export.py index f46a08b406..30534334df 100644 --- a/zerver/management/commands/export.py +++ b/zerver/management/commands/export.py @@ -32,7 +32,7 @@ class Command(ZulipBaseCommand): * Users' passwords and API keys (users will need to use SSO or reset password) * Mobile tokens for APNS/GCM (users will need to reconnect their mobile devices) * ScheduledEmail (Not relevant on a new server) - * Deployment (Unused) + * RemoteZulipServer (Unlikely to be migrated) * third_party_api_results cache (this means rerending all old messages could be expensive) diff --git a/zerver/tests/test_messages.py b/zerver/tests/test_messages.py index d65e65a67b..b7908a7f36 100644 --- a/zerver/tests/test_messages.py +++ b/zerver/tests/test_messages.py @@ -9,7 +9,6 @@ from zerver.decorator import JsonableError from zerver.lib.test_runner import slow from zerver.lib.cache import get_stream_cache_key, cache_delete from zerver.lib.str_utils import force_text -from zilencer.models import Deployment from zerver.lib.addressee import Addressee @@ -181,17 +180,6 @@ class TestCrossRealmPMs(ZulipTestCase): RealmDomain.objects.create(realm=realm, domain=domain) return realm - def setUp(self): - # type: () -> None - dep = Deployment() - dep.base_api_url = "https://zulip.com/api/" - dep.base_site_url = "https://zulip.com/" - # We need to save the object before we can access - # the many-to-many relationship 'realms' - dep.save() - dep.realms = [get_realm("zulip")] - dep.save() - def create_user(self, email): # type: (Text) -> UserProfile subdomain = email.split("@")[1] @@ -203,13 +191,9 @@ class TestCrossRealmPMs(ZulipTestCase): 'support@3.example.com']) def test_realm_scenarios(self): # type: () -> None - r1 = self.make_realm('1.example.com') + self.make_realm('1.example.com') r2 = self.make_realm('2.example.com') - r3 = self.make_realm('3.example.com') - deployment = Deployment.objects.filter()[0] - deployment.realms.add(r1) - deployment.realms.add(r2) - deployment.realms.add(r3) + self.make_realm('3.example.com') def assert_message_received(to_user, from_user): # type: (UserProfile, UserProfile) -> None diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 619e22969d..06b7369ef1 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -12,7 +12,6 @@ from zerver.lib.test_helpers import MockLDAP from confirmation.models import Confirmation, create_confirmation_link, MultiuseInvite, \ generate_key, confirmation_url -from zilencer.models import Deployment from zerver.forms import HomepageForm, WRONG_SUBDOMAIN_ERROR from zerver.lib.actions import do_change_password, gather_subscriptions diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py index e455de95a0..ee26b6e6fb 100644 --- a/zerver/tests/test_upload.py +++ b/zerver/tests/test_upload.py @@ -24,7 +24,6 @@ from zerver.lib.actions import ( do_delete_old_unclaimed_attachments, internal_send_private_message, ) -from zilencer.models import Deployment from zerver.views.upload import upload_file_backend @@ -451,19 +450,8 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): user2_email = 'test-og-bot@zulip.com' user3_email = 'other-user@uploadtest.example.com' - dep = Deployment() - dep.base_api_url = "https://zulip.com/api/" - dep.base_site_url = "https://zulip.com/" - # We need to save the object before we can access - # the many-to-many relationship 'realms' - dep.save() - dep.realms = [get_realm("zulip")] - dep.save() - r1 = Realm.objects.create(string_id=test_subdomain, invite_required=False) RealmDomain.objects.create(realm=r1, domain=test_subdomain) - deployment = Deployment.objects.filter()[0] - deployment.realms.add(r1) create_user(user1_email, test_subdomain) create_user(user2_email, 'zulip') diff --git a/zilencer/migrations/0004_remove_deployment_model.py b/zilencer/migrations/0004_remove_deployment_model.py new file mode 100644 index 0000000000..eb40d378bf --- /dev/null +++ b/zilencer/migrations/0004_remove_deployment_model.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-10-12 06:27 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('zilencer', '0003_add_default_for_remotezulipserver_last_updated_field'), + ] + + operations = [ + migrations.RemoveField( + model_name='deployment', + name='realms', + ), + migrations.DeleteModel( + name='Deployment', + ), + ] diff --git a/zilencer/models.py b/zilencer/models.py index 2a1a31eaac..47f21417a5 100644 --- a/zilencer/models.py +++ b/zilencer/models.py @@ -22,30 +22,3 @@ 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 - -class Deployment(models.Model): - realms = models.ManyToManyField(zerver.models.Realm, - related_name="_deployments") # type: Manager - is_active = models.BooleanField(default=True) # type: bool - - # TODO: This should really become the public portion of a keypair, and - # it should be settable only with an initial bearer "activation key" - api_key = models.CharField(max_length=32, null=True) # type: Optional[Text] - - base_api_url = models.CharField(max_length=128) # type: Text - base_site_url = models.CharField(max_length=128) # type: Text - - @property - def endpoints(self): - # type: () -> Dict[str, Text] - return {'base_api_url': self.base_api_url, 'base_site_url': self.base_site_url} - - @property - def name(self): - # type: () -> Text - - # 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. - # This also doesn't necessarily handle other multi-realm deployments correctly - return self.realms.order_by('pk')[0].domain diff --git a/zilencer/urls.py b/zilencer/urls.py index c641b12a64..5fed170cfe 100644 --- a/zilencer/urls.py +++ b/zilencer/urls.py @@ -10,8 +10,6 @@ i18n_urlpatterns = [] # type: Any # Zilencer views following the REST API style v1_api_and_json_patterns = [ - url('^deployment/report_error$', rest_dispatch, - {'POST': 'zerver.views.report.report_error'}), url('^remotes/push/register$', rest_dispatch, {'POST': 'zilencer.views.remote_server_register_push'}), url('^remotes/push/unregister$', rest_dispatch, diff --git a/zilencer/views.py b/zilencer/views.py index 10ad297d99..1bd354d624 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -3,10 +3,9 @@ from django.utils.translation import ugettext as _ from django.utils import timezone from django.http import HttpResponse, HttpRequest -from zilencer.models import Deployment, RemotePushDeviceToken, RemoteZulipServer +from zilencer.models import RemotePushDeviceToken, RemoteZulipServer from zerver.decorator import has_request_variables, REQ -from zerver.lib.error_notify import do_report_error from zerver.lib.push_notifications import send_android_push_notification, \ send_apple_push_notification from zerver.lib.request import JsonableError @@ -29,11 +28,6 @@ def validate_bouncer_token_request(entity, token, kind): validate_entity(entity) validate_token(token, kind) -@has_request_variables -def report_error(request, deployment, type=REQ(), report=REQ(validator=check_dict([]))): - # type: (HttpRequest, Deployment, Text, Dict[str, Any]) -> HttpResponse - return do_report_error(deployment.name, type, report) - @has_request_variables def remote_server_register_push(request, entity, user_id=REQ(), token=REQ(), token_kind=REQ(validator=check_int), ios_app_id=None):