From 4f0f734810da262044d9ec3ba6baacb73908468e Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 26 Aug 2020 15:47:43 -0700 Subject: [PATCH] urls: Simplify URL patterns for presence. Extracting a section for presence endpoints and using path() rather than re_path() results in a much cleaner implementation of this concept. This eliminates the last case where test_openapi couldn't correctly match an endpoint documentation with the OpenAPI definitions for it. --- zerver/tests/test_openapi.py | 4 ---- zproject/urls.py | 19 +++++++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py index 964f43fc3d..778387240f 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[^/]*)/presence', } # Endpoints where the documentation is currently failing our diff --git a/zproject/urls.py b/zproject/urls.py index f2f43a1bd6..92c76f84a9 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//reactivate', rest_dispatch, {'POST': 'zerver.views.users.reactivate_user_backend'}), - re_path(r'^users/(?!me/)(?P[^/]*)/presence$', rest_dispatch, - {'GET': 'zerver.views.presence.get_presence_backend'}), path('users/', 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//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'}),