Repository: mdn/kuma

Issue:
🧹 Remove hompage related frontend code
Once https://github.com/mdn/yari/issues/2438 lands, we need to go into the Kuma forest and find all things related to the homepage frontend code, chop it down, and clear it out.


Discussion:
I think we should instead delete ALL front-end code. Absolutely everything. Every .scss and every .js and all the hacky solutions in `settings/common.py` related to django-pipeline. 
The only "HTML'y" thing worth keeping is the Django Admin and I think that's not using any tricky tricks. 
> I think we should instead delete ALL front-end code. Absolutely everything. Every .scss and every .js and all the hacky solutions in `settings/common.py` related to django-pipeline.
> The only "HTML'y" thing worth keeping is the Django Admin and I think that's not using any tricky tricks.

Agreed, but I was thinking of doing it carefully and piece by piece as we implement and roll out the relevant pieces on Yari.
What we can do is what Ryan did here: https://github.com/mdn/kuma/pull/7746
Just many little PRs (which is sane) that deal with some small little slice and just keep saying `Part of #7740`

Resolving patch:
diff --git a/kuma/landing/urls.py b/kuma/landing/urls.py
--- a/kuma/landing/urls.py
+++ b/kuma/landing/urls.py
@@ -11,12 +11,9 @@
 lang_urlpatterns = [
     re_path(r"^$", views.home, name="home"),
     re_path(r"^maintenance-mode/?$", views.maintenance_mode, name="maintenance_mode"),
-    re_path(r"^promote/?$", views.promote_buttons, name="promote"),
-    re_path(r"^promote/buttons/?$", views.promote_buttons, name="promote_buttons"),
 ]
 
 urlpatterns = [
-    re_path(r"^contribute\.json$", views.contribute_json, name="contribute_json"),
     re_path(r"^robots.txt$", views.robots_txt, name="robots_txt"),
     re_path(
         r"^favicon.ico$",
diff --git a/kuma/landing/views.py b/kuma/landing/views.py
--- a/kuma/landing/views.py
+++ b/kuma/landing/views.py
@@ -1,37 +1,25 @@
 from django.conf import settings
 from django.http import HttpResponse
 from django.shortcuts import redirect, render
-from django.views import static
 from django.views.decorators.cache import never_cache
 from django.views.generic import RedirectView
 
 from kuma.core.decorators import ensure_wiki_domain, shared_cache_control
-from kuma.core.utils import is_wiki
-from kuma.feeder.models import Bundle
-from kuma.feeder.sections import SECTION_HACKS
-from kuma.search.models import Filter
 
 from .utils import favicon_url
 
 
-@shared_cache_control
-def contribute_json(request):
-    return static.serve(request, "contribute.json", document_root=settings.ROOT)
-
-
-@shared_cache_control
 def home(request):
     """Home page."""
-    context = {}
-    # Need for both wiki and react homepage
-    context["updates"] = list(Bundle.objects.recent_entries(SECTION_HACKS.updates)[:5])
-
-    # The default template name
-    template_name = "landing/react_homepage.html"
-    if is_wiki(request):
-        template_name = "landing/homepage.html"
-        context["default_filters"] = Filter.objects.default_filters()
-    return render(request, template_name, context)
+    return HttpResponse(
+        """
+    <html>
+    End of an era. Kuma's no longer rendering a home page.<br>
+    See project Yari.
+    </html>
+    """,
+        content_type="text/html",
+    )
 
 
 @ensure_wiki_domain
@@ -43,13 +31,6 @@ def maintenance_mode(request):
         return redirect("home")
 
 
-@ensure_wiki_domain
-@shared_cache_control
-def promote_buttons(request):
-    """Bug 646192: MDN affiliate buttons"""
-    return render(request, "landing/promote_buttons.html")
-
-
 ROBOTS_ALL_ALLOWED_TXT = """\
 User-agent: *
 Sitemap: https://wiki.developer.mozilla.org/sitemap.xml


Test patch:
diff --git a/kuma/core/tests/test_middleware.py b/kuma/core/tests/test_middleware.py
--- a/kuma/core/tests/test_middleware.py
+++ b/kuma/core/tests/test_middleware.py
@@ -13,35 +13,6 @@
 )
 
 
-@pytest.mark.parametrize("path", ("/missing_url", "/missing_url/"))
-def test_slash_middleware_keep_404(client, db, path):
-    """The SlashMiddleware retains 404s."""
-    response = client.get(path)
-    assert response.status_code == 404
-
-
-def test_slash_middleware_removes_slash(client, db):
-    """The SlashMiddleware fixes a URL that shouldn't have a trailing slash."""
-    response = client.get("/contribute.json/")
-    assert response.status_code == 301
-    assert response["Location"].endswith("/contribute.json")
-
-
-@pytest.mark.parametrize("path", ("/admin", "/en-US"))
-def test_slash_middleware_adds_slash(path, client, db):
-    """The SlashMiddleware fixes a URL that should have a trailing slash."""
-    response = client.get(path)
-    assert response.status_code == 301
-    assert response["Location"].endswith(path + "/")
-
-
-def test_slash_middleware_retains_querystring(client, db):
-    """The SlashMiddleware handles encoded querystrings."""
-    response = client.get("/contribute.json/?xxx=%C3%83")
-    assert response.status_code == 301
-    assert response["Location"].endswith("/contribute.json?xxx=%C3%83")
-
-
 @pytest.mark.parametrize(
     "forwarded_for,remote_addr",
     (("1.1.1.1", "1.1.1.1"), ("2.2.2.2", "2.2.2.2"), ("3.3.3.3, 4.4.4.4", "3.3.3.3")),
diff --git a/kuma/core/tests/test_views.py b/kuma/core/tests/test_views.py
--- a/kuma/core/tests/test_views.py
+++ b/kuma/core/tests/test_views.py
@@ -1,18 +1,13 @@
 import logging
-from unittest import mock
 
 import pytest
 from django.conf import settings
 from django.core import mail
 from django.test import override_settings
 from django.utils.log import AdminEmailHandler
-from pyquery import PyQuery as pq
-from ratelimit.exceptions import Ratelimited
-from soapbox.models import Message
 
 from . import assert_no_cache_header, KumaTestCase
 from ..urlresolvers import reverse
-from ..views import handler500
 
 
 @override_settings(
@@ -49,30 +44,6 @@ def test_mail_handler(self):
         assert self.suspicous_path in mail.outbox[0].body
 
 
-class SoapboxViewsTest(KumaTestCase):
-    def test_global_home(self):
-        m = Message(message="Global", is_global=True, is_active=True, url="/")
-        m.save()
-
-        url = reverse("home")
-        r = self.client.get(url, follow=True)
-        assert 200 == r.status_code
-
-        doc = pq(r.content)
-        assert m.message == doc.find("div.global-notice").text()
-
-    def test_inactive(self):
-        m = Message(message="Search", is_global=False, is_active=False, url="/search/")
-        m.save()
-
-        url = reverse("home")
-        r = self.client.get(url, follow=True)
-        assert 200 == r.status_code
-
-        doc = pq(r.content)
-        assert not doc.find("div.global-notice")
-
-
 class EventsRedirectTest(KumaTestCase):
     def test_redirect_to_mozilla_org(self):
         url = "/en-US/events"
@@ -111,32 +82,3 @@ def test_not_possible_to_set_non_locale_cookie(client):
     assert_no_cache_header(response)
     # No language cookie should be saved as `foo` is not a supported locale
     assert not response.client.cookies.get(settings.LANGUAGE_COOKIE_NAME)
-
-
-def test_ratelimit_429(client, db):
-    """Custom 429 view is used for Ratelimited exception."""
-    url = reverse("home")
-    with mock.patch("kuma.landing.views.render") as render:
-        render.side_effect = Ratelimited()
-        response = client.get(url)
-    assert response.status_code == 429
-    assert "429.html" in [t.name for t in response.templates]
-    assert response["Retry-After"] == "60"
-    assert_no_cache_header(response)
-
-
-def test_error_handler_minimal_request(rf, db, settings):
-    """Error page renders if middleware hasn't added request members."""
-    # Setup conditions for adding analytics with a flag check
-    settings.GOOGLE_ANALYTICS_ACCOUNT = "UA-00000000-0"
-
-    # Create minimal request
-    request = rf.get("/en-US/docs/tags/Open Protocol")
-    assert not hasattr(request, "LANGUAGE_CODE")
-    assert not hasattr(request, "user")
-
-    # Generate the 500 page
-    exception = Exception("Something went wrong.")
-    response = handler500(request, exception)
-    assert response.status_code == 500
-    assert b"Internal Server Error" in response.content
diff --git a/kuma/landing/tests/test_templates.py b/kuma/landing/tests/test_templates.py
deleted file mode 100644
--- a/kuma/landing/tests/test_templates.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from pyquery import PyQuery as pq
-
-from kuma.core.urlresolvers import reverse
-from kuma.search.models import Filter, FilterGroup
-
-
-def test_google_analytics_disabled(db, settings, client):
-    settings.GOOGLE_ANALYTICS_ACCOUNT = None
-    response = client.get(reverse("home"), follow=True)
-    assert 200 == response.status_code
-    assert b"ga('create" not in response.content
-
-
-def test_google_analytics_enabled(db, settings, client):
-    settings.GOOGLE_ANALYTICS_ACCOUNT = "UA-99999999-9"
-    response = client.get(reverse("home"), follow=True)
-    assert 200 == response.status_code
-    assert b"ga('create" in response.content
-
-
-def test_default_search_filters(db, settings, client):
-    group = FilterGroup.objects.create(name="Topic", slug="topic")
-    for name in ["CSS", "HTML", "JavaScript"]:
-        Filter.objects.create(group=group, name=name, slug=name.lower(), default=True)
-
-    response = client.get(reverse("home"), follow=True, HTTP_HOST=settings.WIKI_HOST)
-    page = pq(response.content)
-    filters = page.find("#home-search-form input[type=hidden]")
-
-    assert "topic" == filters.eq(0).attr("name")
-    assert set(p.val() for p in filters.items()) == {"css", "html", "javascript"}
diff --git a/kuma/landing/tests/test_views.py b/kuma/landing/tests/test_views.py
--- a/kuma/landing/tests/test_views.py
+++ b/kuma/landing/tests/test_views.py
@@ -1,13 +1,10 @@
-from unittest import mock
 from urllib.parse import urlparse
 
 import pytest
 from django.core.cache import cache
-from ratelimit.exceptions import Ratelimited
 
 from kuma.core.tests import (
     assert_no_cache_header,
-    assert_redirect_to_wiki,
     assert_shared_cache_header,
 )
 from kuma.core.urlresolvers import reverse
@@ -20,39 +17,6 @@ def cleared_cache():
     cache.clear()
 
 
-def test_contribute_json(client, db):
-    response = client.get(reverse("contribute_json"))
-    response.close()  # Discard response body; prevents an unclosed file warning
-    assert response.status_code == 200
-    assert_shared_cache_header(response)
-    assert response["Content-Type"].startswith("application/json")
-
-
-@pytest.mark.parametrize("case", ("DOMAIN", "WIKI_HOST"))
-def test_home(client, db, settings, case):
-    response = client.get(
-        reverse("home", locale="en-US"), HTTP_HOST=getattr(settings, case)
-    )
-    assert response.status_code == 200
-    assert_shared_cache_header(response)
-    if case == "WIKI_HOST":
-        expected_template = "landing/homepage.html"
-    else:
-        expected_template = "landing/react_homepage.html"
-    assert expected_template in (t.name for t in response.templates)
-
-
-@mock.patch("kuma.landing.views.render")
-def test_home_when_rate_limited(mock_render, client, db):
-    """
-    Cloudfront CDN's don't cache 429's, but let's test this anyway.
-    """
-    mock_render.side_effect = Ratelimited()
-    response = client.get(reverse("home"))
-    assert response.status_code == 429
-    assert_no_cache_header(response)
-
-
 @pytest.mark.parametrize("mode", ["maintenance", "normal"])
 def test_maintenance_mode(db, client, settings, mode):
     url = reverse("maintenance_mode")
@@ -68,12 +32,6 @@ def test_maintenance_mode(db, client, settings, mode):
     assert_no_cache_header(response)
 
 
-def test_promote_buttons(client, db):
-    response = client.get(reverse("promote_buttons"), follow=True)
-    assert response.status_code == 200
-    assert_shared_cache_header(response)
-
-
 def test_robots_not_allowed(client):
     """By default, robots.txt shows that robots are not allowed."""
     response = client.get(reverse("robots_txt"))
@@ -137,11 +95,3 @@ def test_favicon_ico(client, settings):
     assert response.status_code == 302
     assert_shared_cache_header(response)
     assert response["Location"] == "/static/img/favicon32-local.png"
-
-
-@pytest.mark.parametrize("endpoint", ["maintenance_mode", "promote", "promote_buttons"])
-def test_redirect(client, endpoint):
-    """Redirect to the wiki domain if not already."""
-    url = reverse(endpoint)
-    response = client.get(url)
-    assert_redirect_to_wiki(response, url)
diff --git a/kuma/scrape/tests/test_source_links.py b/kuma/scrape/tests/test_source_links.py
--- a/kuma/scrape/tests/test_source_links.py
+++ b/kuma/scrape/tests/test_source_links.py
@@ -36,34 +36,6 @@ def test_init_non_english():
     assert source.locale == "fr"
 
 
-def test_gather_homepage(client, db):
-    source = LinksSource("/")
-    html = client.get("/en-US/", HTTP_HOST=settings.WIKI_HOST).content
-    requester = mock_requester(content=html)
-    storage = mock_storage()
-    resources = source.gather(requester, storage)
-    assert source.state == source.STATE_DONE
-    assert source.freshness == source.FRESH_YES
-
-    # The exact list of resources will change as the homepage changes
-    expected_paths = [
-        "/en-US/docs/Learn",
-        "/en-US/docs/Tools",
-        "/en-US/docs/Web/JavaScript",
-    ]
-    for path in expected_paths:
-        spec = ("document", path, {})
-        assert spec in resources
-
-    # These appear on the homepage, but shouldn't be in the paths to scrape
-    unexpected_paths = [
-        "/en-US/search",
-    ]
-    for path in unexpected_paths:
-        spec = ("document", path, {})
-        assert spec not in resources
-
-
 def test_gather_ignores_links(client, root_doc, simple_user):
     user_profile_url = simple_user.get_absolute_url()
     content = (
diff --git a/kuma/users/tests/test_templates.py b/kuma/users/tests/test_templates.py
--- a/kuma/users/tests/test_templates.py
+++ b/kuma/users/tests/test_templates.py
@@ -164,36 +164,6 @@ def test_signup(self):
         assert response.status_code == 302
         assert_no_cache_header(response)
 
-        # The rest of this test simply gets and checks the wiki home page.
-        response = self.client.get(
-            response["Location"], follow=True, HTTP_HOST=settings.WIKI_HOST
-        )
-        assert response.status_code == 200
-
-        user_url = reverse("users.user_detail", kwargs={"username": username})
-        logout_url = reverse("account_logout")
-        home_url = reverse("home")
-        signout_url = urlparams(logout_url)
-        parsed = pq(response.content)
-
-        login_info = parsed.find(".login")
-        # Check login user url is there
-        user_link = login_info.children(".user-url")
-        assert user_link.attr["href"] == user_url
-
-        form = login_info.find("form")
-        # There should be signout link in the form action
-        expected = signout_url.replace("%2F", "/")  # decode slashes
-        assert form.attr["action"] == expected
-        assert form.attr["method"] == "post"
-        # Check next url is provided as input field
-        next_input = form.children("input[name='next']")
-        assert next_input.val() == home_url
-        # Ensure CSRF protection has not been added, since it creates problems
-        # when used with a CDN like CloudFront (see bugzilla #1456165).
-        csrf_input = form.children("input[name='csrfmiddlewaretoken']")
-        assert not csrf_input
-
 
 class BanTestCase(UserTestCase):
     def test_common_reasons_in_template(self):
diff --git a/kuma/wiki/tests/test_templates.py b/kuma/wiki/tests/test_templates.py
--- a/kuma/wiki/tests/test_templates.py
+++ b/kuma/wiki/tests/test_templates.py
@@ -4,7 +4,7 @@
 
 import pytest
 from django.conf import settings
-from django.contrib.auth.models import AnonymousUser, Group
+from django.contrib.auth.models import AnonymousUser
 from django.contrib.sites.models import Site
 from django.core import mail
 from django.shortcuts import render
@@ -19,7 +19,6 @@
 )
 from kuma.core.urlresolvers import reverse
 from kuma.core.utils import urlparams
-from kuma.users.models import User
 from kuma.users.tests import UserTestCase
 
 from . import (
@@ -474,48 +473,6 @@ def test_orphan_doc(self):
         dim17 = "ga('set', 'dimension17',"
         assert dim17 not in content
 
-    def test_anon_user(self):
-        response = self.client.get("/en-US/", HTTP_HOST=settings.WIKI_HOST)
-        assert response.status_code == 200
-        content = response.content.decode(response.charset)
-        assert self.ga_create in content
-        assert self.dim1 not in content
-        assert self.dim2 not in content
-        assert self.dim18 not in content
-
-    def test_regular_user(self):
-        assert self.client.login(username="testuser", password="testpass")
-        response = self.client.get("/en-US/", HTTP_HOST=settings.WIKI_HOST)
-        assert response.status_code == 200
-        content = response.content.decode(response.charset)
-        assert self.ga_create in content
-        assert self.dim1 in content
-        assert self.dim2 not in content
-        assert self.dim18 not in content
-
-    def test_beta_user(self):
-        testuser = User.objects.get(username="testuser")
-        beta = Group.objects.get(name="Beta Testers")
-        testuser.groups.add(beta)
-        assert self.client.login(username="testuser", password="testpass")
-        response = self.client.get("/en-US/", HTTP_HOST=settings.WIKI_HOST)
-        assert response.status_code == 200
-        content = response.content.decode(response.charset)
-        assert self.ga_create in content
-        assert self.dim1 in content
-        assert self.dim2 in content
-        assert self.dim18 not in content
-
-    def test_staff_user(self):
-        assert self.client.login(username="admin", password="testpass")
-        response = self.client.get("/en-US/", HTTP_HOST=settings.WIKI_HOST)
-        assert response.status_code == 200
-        content = response.content.decode(response.charset)
-        assert self.ga_create in content
-        assert self.dim1 in content
-        assert self.dim2 not in content
-        assert self.dim18 in content
-
 
 def test_revision_template(root_doc, client):
     """Verify the revision template."""