Skip to content

Commit

Permalink
Notifications: allow usernames with dots (#11283)
Browse files Browse the repository at this point in the history
* Notifications: allow usernames with dots

Closes #11260

* Test
  • Loading branch information
stsewd committed Apr 23, 2024
1 parent ea333be commit 9d91087
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions readthedocs/api/v3/tests/test_users.py
Expand Up @@ -53,6 +53,21 @@ def test_users_notifications_list(self):
self._get_response_dict("users-notifications-list"),
)

def test_users_notifications_list_with_email_like_username(self):
"""Test for #11260."""
self.me.username = "test@example.com"
self.me.save()
url = reverse(
"users-notifications-list",
kwargs={
"parent_lookup_user__username": self.me.username,
},
)

self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token.key}")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

def test_users_notifications_list_other_user(self):
url = reverse(
"users-notifications-list",
Expand Down
4 changes: 4 additions & 0 deletions readthedocs/api/v3/views.py
Expand Up @@ -589,6 +589,10 @@ class UsersViewSet(
serializer_class = UserSerializer
queryset = User.objects.none()
permission_classes = (IsAuthenticated,)
# We are using the username as the lookup field,
# by default, DRF does not allow dots and `/`,
# but we allow usernames to have dots.
lookup_value_regex = "[^/]+"


class NotificationsUserViewSet(
Expand Down

0 comments on commit 9d91087

Please sign in to comment.