Skip to content

Commit

Permalink
zilencer: Clean up logic around mobile push notifications signup.
Browse files Browse the repository at this point in the history
This fixes exceptions when sending PMs in development (where we were
trying to connect to the localhost push bouncer, which we weren't
authorized for, but even if we were, it wouldn't work, since there's
no APNS/GCM certs).

At the same time, we also set and order of operations that ensures one
has the opportunity to adjust the server URL before submitting
anything to us.
  • Loading branch information
timabbott committed May 5, 2018
1 parent 6817232 commit cfd22c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
14 changes: 7 additions & 7 deletions docs/production/mobile-push-notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ support forwarding push notifications to a central push notification
forwarding service. You can enable this for your Zulip server as
follows:

1. If you're running Zulip 1.8.1 or newer, you can run `manage.py
register_server` from `/home/zulip/deployments/current`. This
command will print the registration data it would send to the
mobile push notifications service, ask you to accept the terms of
service, and if you accept, register your server. Otherwise, see
the [legacy signup instructions](#legacy-signup).

1. Uncomment the `PUSH_NOTIFICATION_BOUNCER_URL =
'https://push.zulipchat.com'` line in your `/etc/zulip/settings.py`
file (i.e. remove the `#` at the start of the line), and
[restart your Zulip server](../production/maintain-secure-upgrade.html#updating-settings).
If you installed your Zulip server with a version older than 1.6,
you'll need to add the line (it won't be there to uncomment).

1. If you're running Zulip 1.8.1 or newer, you can run `manage.py
register_server` from `/home/zulip/deployments/current`. This
command will print the registration data it would send to the
mobile push notifications service, ask you to accept the terms of
service, and if you accept, register your server. Otherwise, see
the [legacy signup instructions](#legacy-signup).

1. If you or your users have already set up the Zulip mobile app,
you'll each need to log out and log back in again in order to start
getting push notifications.
Expand Down
11 changes: 9 additions & 2 deletions zerver/management/commands/register_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def add_arguments(self, parser: ArgumentParser) -> None:
help="Automatically rotate your server's zulip_org_key")

def handle(self, **options: Any) -> None:
check_config()
if not settings.DEVELOPMENT:
check_config()

if not options['agree_to_terms_of_service'] and not options["rotate_key"]:
raise CommandError(
Expand All @@ -43,6 +44,13 @@ def handle(self, **options: Any) -> None:
raise CommandError("Missing zulip_org_id; run scripts/setup/generate_secrets.py to generate.")
if not settings.ZULIP_ORG_KEY:
raise CommandError("Missing zulip_org_key; run scripts/setup/generate_secrets.py to generate.")
if settings.PUSH_NOTIFICATION_BOUNCER_URL is None:
if settings.DEVELOPMENT:
settings.PUSH_NOTIFICATION_BOUNCER_URL = (settings.EXTERNAL_URI_SCHEME +
settings.EXTERNAL_HOST)
else:
raise CommandError("Please uncomment PUSH_NOTIFICATION_BOUNCER_URL "
"in /etc/zulip/settings.py (remove the '#')")

request = {
"zulip_org_id": settings.ZULIP_ORG_ID,
Expand Down Expand Up @@ -77,7 +85,6 @@ def handle(self, **options: Any) -> None:
if response.json()['created']:
print("You've successfully register for the Mobile Push Notification Service!\n"
"To finish setup for sending push notifications:")
print("- Uncomment PUSH_NOTIFICATION_BOUNCER_URL in /etc/zulip/settings.py (remove the '#')")
print("- Restart the server, using /home/zulip/deployments/current/scripts/restart-server")
print("- Return to the documentation to learn how to test push notifications")
else:
Expand Down
1 change: 0 additions & 1 deletion zproject/dev_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,3 @@

# Set this True to send all hotspots in development
ALWAYS_SEND_ALL_HOTSPOTS = False # type: bool
PUSH_NOTIFICATION_BOUNCER_URL = EXTERNAL_URI_SCHEME + EXTERNAL_HOST

0 comments on commit cfd22c6

Please sign in to comment.