Repository: mdn/kuma

Issue:
Clean away api.v1.views.get_user
(We chatted about this on email, so I'm just going to paste that in here)

Ryan added this Nov 15, 2019 and I think it was pre-emptively to suppose some sort of
SPA during the sign up process. I.e. client-side validation of the username you prefer
https://github.com/mdn/kuma/commit/144d8ab40213ec4bbf36c7c940f1d2bf9c54b909

I'm pretty confident we're NOT using it. The sign-up does that username checking based on
allauth.socialaccount.forms.SignupForm which we use here https://github.com/mdn/kuma/blob/20670f94b95b5dfad52165c2483e283f7d7375e5/kuma/users/signup.py

Also, I know all these pieces of data are all available by simply going to
https://wiki.developer.mozilla.org/en-US/profiles/$username
and scrape the HTML.
But given that we have no use for it and when we go to Yari 2, we'll need a new sign up form, we might still not need this because we might just do the same thing there; that you pick a username and HTTP POST submit and if it works it worked.

So any objections to me deleting it?




Discussion:
I can't even remember why I added that, so I say dump it! Thanks @peterbe.

Resolving patch:
diff --git a/kuma/api/v1/urls.py b/kuma/api/v1/urls.py
--- a/kuma/api/v1/urls.py
+++ b/kuma/api/v1/urls.py
@@ -8,7 +8,6 @@
     re_path(r"^whoami/?$", views.whoami, name="api.v1.whoami"),
     re_path(r"^search/(?P<locale>[^/]+)/?$", views.search, name="api.v1.search"),
     re_path(r"^bc-signal/?$", views.bc_signal, name="api.v1.bc_signal"),
-    re_path(r"^users/(?P<username>[^/]+)/?$", views.get_user, name="api.v1.get_user"),
     path(
         "subscriptions/feedback/",
         views.send_subscriptions_feedback,
diff --git a/kuma/api/v1/views.py b/kuma/api/v1/views.py
--- a/kuma/api/v1/views.py
+++ b/kuma/api/v1/views.py
@@ -2,7 +2,6 @@
 
 from django.conf import settings
 from django.http import (
-    Http404,
     HttpResponse,
     HttpResponseBadRequest,
     HttpResponsePermanentRedirect,
@@ -11,7 +10,7 @@
 from django.shortcuts import get_object_or_404
 from django.utils.translation import activate, gettext as _
 from django.views.decorators.cache import never_cache
-from django.views.decorators.http import require_GET, require_POST, require_safe
+from django.views.decorators.http import require_GET, require_POST
 from ratelimit.decorators import ratelimit
 from rest_framework import serializers, status
 from rest_framework.decorators import api_view
@@ -36,7 +35,7 @@
     TagGroupFilterBackend,
 )
 from kuma.search.search import SearchView
-from kuma.users.models import User, UserSubscription
+from kuma.users.models import UserSubscription
 from kuma.users.stripe_utils import (
     cancel_stripe_customer_subscriptions,
     create_stripe_customer_and_subscription_for_user,
@@ -321,33 +320,6 @@ def bc_signal(request):
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
 
 
-@never_cache
-@require_safe
-def get_user(request, username):
-    """
-    Returns a JSON response with a small subset of public information if a
-    user with the given username exists, otherwise returns a status code of
-    404. The case of the username is not important, since the collation of
-    the username column of the user table in MySQL is case-insensitive.
-    """
-    fields = (
-        "username",
-        "title",
-        "fullname",
-        "organization",
-        "location",
-        "timezone",
-        "locale",
-    )
-    try:
-        user = User.objects.only(*fields).get(username=username)
-    except User.DoesNotExist:
-        raise Http404(f'No user exists with the username "{username}".')
-    data = {field: getattr(user, field) for field in fields}
-    data["avatar_url"] = get_avatar_url(user)
-    return JsonResponse(data)
-
-
 @waffle_flag("subscription")
 @never_cache
 @require_POST


Test patch:
diff --git a/kuma/api/v1/tests/test_views.py b/kuma/api/v1/tests/test_views.py
--- a/kuma/api/v1/tests/test_views.py
+++ b/kuma/api/v1/tests/test_views.py
@@ -349,59 +349,6 @@ def test_search_basic(self):
         assert data["locale"] == "fr"
 
 
-@pytest.mark.parametrize("http_method", ("put", "post", "delete", "options"))
-def test_get_user_disallowed_methods(client, wiki_user, http_method):
-    """
-    HTTP methods other than GET and HEAD are not allowed on the api.v1.get_user
-    endpoint.
-    """
-    url = reverse("api.v1.get_user", args=(wiki_user.username,))
-    response = getattr(client, http_method)(url)
-    assert response.status_code == 405
-    assert_no_cache_header(response)
-
-
-@pytest.mark.parametrize("case", ("upper", "lower"))
-@pytest.mark.parametrize("http_method", ("get", "head"))
-def test_get_existing_user(
-    client, wiki_user, wiki_user_github_account, http_method, case
-):
-    """
-    Test GET and HEAD on the api.v1.get_user endpoint for an existing user, and
-    also that the username is case insensitive.
-    """
-    username = getattr(str, case)(wiki_user.username)
-    url = reverse("api.v1.get_user", args=(username,))
-    response = getattr(client, http_method)(url)
-    assert response.status_code == 200
-    assert response["content-type"] == "application/json"
-    assert_no_cache_header(response)
-    if http_method == "get":
-        data = response.json()
-        assert data["username"] == wiki_user.username
-        assert data["avatar_url"] == wiki_user_github_account.get_avatar_url()
-        for field in (
-            "title",
-            "fullname",
-            "organization",
-            "location",
-            "timezone",
-            "locale",
-        ):
-            assert data[field] == getattr(wiki_user, field)
-
-
-@pytest.mark.parametrize("http_method", ("get", "head"))
-def test_get_nonexisting_user(db, client, http_method):
-    """
-    Test GET and HEAD on the api.v1.get_user endpoint for a non-existing user.
-    """
-    url = reverse("api.v1.get_user", args=("nonexistent",))
-    response = getattr(client, http_method)(url)
-    assert response.status_code == 404
-    assert_no_cache_header(response)
-
-
 @pytest.mark.django_db
 def test_bc_signal_happy_path(client, root_doc):
     url = reverse("api.v1.bc_signal")