Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

urls: Simplify URL patterns for presence.

Tim Abbott4f0f734810da
diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py
index 964f43fc3d3..778387240f5 100644
--- a/zerver/tests/test_openapi.py
+++ b/zerver/tests/test_openapi.py
@@ -290,10 +290,6 @@ class OpenAPIArgumentsTest(ZulipTestCase):
'/fetch_google_client_id',
# API for video calls we're planning to remove/replace.
'/calls/zoom/create',
-
- #### Documented endpoints not properly detected by tooling.
- # Regex with an unnamed capturing group.
- '/users/(?!me/)(?P<email>[^/]*)/presence',
}
# Endpoints where the documentation is currently failing our
diff --git a/zproject/urls.py b/zproject/urls.py
index f2f43a1bd62..92c76f84a90 100644
--- a/zproject/urls.py
+++ b/zproject/urls.py
@@ -138,19 +138,11 @@ v1_api_and_json_patterns = [
{'GET': 'zerver.views.presence.get_statuses_for_realm'}),
# users -> zerver.views.users
- #
- # Since some of these endpoints do something different if used on
- # yourself with `/me` as the email, we need to make sure that we
- # don't accidentally trigger these. The cleanest way to do that
- # is to add a regular expression assertion that it isn't `/me/`
- # (or ends with `/me`, in the case of hitting the root URL).
path('users', rest_dispatch,
{'GET': 'zerver.views.users.get_members_backend',
'POST': 'zerver.views.users.create_user_backend'}),
path('users/<int:user_id>/reactivate', rest_dispatch,
{'POST': 'zerver.views.users.reactivate_user_backend'}),
- re_path(r'^users/(?!me/)(?P<email>[^/]*)/presence$', rest_dispatch,
- {'GET': 'zerver.views.presence.get_presence_backend'}),
path('users/<int:user_id>', rest_dispatch,
{'GET': 'zerver.views.users.get_members_backend',
'PATCH': 'zerver.views.users.update_user_backend',
@@ -273,8 +265,6 @@ v1_api_and_json_patterns = [
path('users/me', rest_dispatch,
{'GET': 'zerver.views.users.get_profile_backend',
'DELETE': 'zerver.views.users.deactivate_user_own_backend'}),
- path('users/me/presence', rest_dispatch,
- {'POST': 'zerver.views.presence.update_active_status_backend'}),
path('users/me/status', rest_dispatch,
{'POST': 'zerver.views.presence.update_user_status_backend'}),
# Endpoint used by mobile devices to register their push
@@ -286,6 +276,15 @@ v1_api_and_json_patterns = [
{'POST': 'zerver.views.push_notifications.add_android_reg_id',
'DELETE': 'zerver.views.push_notifications.remove_android_reg_id'}),
+ # users/*/presnece => zerver.views.presence.
+ path('users/me/presence', rest_dispatch,
+ {'POST': 'zerver.views.presence.update_active_status_backend'}),
+ # It's important that this sit after users/me/presence so that
+ # Django's URL resolution order doesn't break the
+ # /users/me/presence endpoint.
+ path(r'users/<str:email>/presence', rest_dispatch,
+ {'GET': 'zerver.views.presence.get_presence_backend'}),
+
# user_groups -> zerver.views.user_groups
path('user_groups', rest_dispatch,
{'GET': 'zerver.views.user_groups.get_user_group'}),