New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remote_server: Add management command for deactivation. #20775
base: main
Are you sure you want to change the base?
Conversation
CodeQL was complaining about |
d291bf0
to
ecb9ce4
Compare
@timabbott This PR is now ready for review! Thanks! :) |
I merged the first commit as 7a1ed9a. |
zilencer/urls.py
Outdated
path("remotes/server/register", register_remote_server), | ||
path("remotes/server/deactivate", deactivate_remote_server), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should use the rest_path
authentication, just like sending a push notification -- the zulip_org_id / zulig_org_key
pair is authentication.
content_dict = response.json() | ||
raise CommandError("Error: " + content_dict["msg"]) | ||
|
||
return response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do this error-handling refactoring in preparatory commits? Renaming this tool is a sensitive operation that will need to be merged carefully, since we don't want to make our documentation confusing, so we want only changes necessary to the renaming operation in that commit.
) | ||
|
||
if response.json()["result"] == "success": | ||
print("Mobile Push Notification Service registration successfully deactivated!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should display some sort of error if this doesn't succeed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Ideally, just the error response returned by the server).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or if _request_push_notification_bouncer_url
ensures it can't have failed, we should have an assert rather than an if
statement.
zerver/lib/exceptions.py
Outdated
|
||
@staticmethod | ||
def msg_format() -> str: | ||
return _("This remote server has been deactivated") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The mobile push notification service registration for your server has been deactivated".
8aba811
to
091e822
Compare
@timabbott I just addressed your feedback. Thanks! |
event_type=RealmAuditLog.REMOTE_SERVER_DEACTIVATED | ||
).last() | ||
assert remote_realm_audit_log is not None | ||
self.assertTrue(server.deactivated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this change, after reordering commits so that the "Fail API requests if deactivated" commit is before this one.
diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py
index f4dd9c34cd..07dfc02b6c 100644
--- a/zerver/tests/test_push_notifications.py
+++ b/zerver/tests/test_push_notifications.py
@@ -2514,6 +2514,16 @@ class PushBouncerSignupTest(ZulipTestCase):
assert remote_realm_audit_log is not None
self.assertTrue(server.deactivated)
+ # Now test that trying to deactivate again reports the right error.
+ result = self.uuid_post(
+ zulip_org_id, "/api/v1/remotes/server/deactivate", request, subdomain=""
+ )
+ self.assert_json_error(
+ result,
+ "The mobile push notification service registration for your server has been deactivated",
+ status_code=401,
+ )
+
def test_push_signup_invalid_host(self) -> None:
zulip_org_id = str(uuid.uuid4())
zulip_org_key = get_random_string(64)
This commit replaces the management command `register_server` with a `mobile_push_service` command with `--register` and `--rotate-key` as subcommands. This allow us to add more subcommands in the future.
091e822
to
b95b1ca
Compare
I merged the series ending with 93329c2 after the small changes noted above and adding a small commit of my own. Thanks for making this reviewable @eeshangarg! The last couple commits remaining on this PR look reasonable, but we need to think carefully about the name for the script as well as how we want to document the change in name. I'll start a chat.zulip.org conversation. |
Heads up @eeshangarg, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
4ec3636
to
88b200c
Compare
Testing plan:
mobile_push_service
management command was tested manually and then the outcome was verified by manually checking the database viapython3 manage.py shell
.