Skip to content

Commit

Permalink
urls: Simplify URL patterns for presence.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
timabbott committed Aug 26, 2020
1 parent 0b77525 commit 4f0f734
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
4 changes: 0 additions & 4 deletions zerver/tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions zproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,11 @@
{'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',
Expand Down Expand Up @@ -273,8 +265,6 @@
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
Expand All @@ -286,6 +276,15 @@
{'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'}),
Expand Down

0 comments on commit 4f0f734

Please sign in to comment.