Skip to content

Commit

Permalink
Add / and /robots.txt functionality after removing it when deleting cms.
Browse files Browse the repository at this point in the history
  • Loading branch information
tadhg-ohiggins committed Nov 2, 2023
1 parent 724e048 commit 7b01951
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
24 changes: 24 additions & 0 deletions backend/audit/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ def _just_uei_workbooks(uei):
return {k: _just_uei(uei, k) for k in workbooks}


class RootPathTests(TestCase):
"""
Do we return the correct response for both authenticated and unauthenticated
users?
"""

def test_unauthenticated(self):
"""Verify the root path returns 200, unauthenticated."""
result = self.client.get("/")
self.assertEqual(result.status_code, 200)

def test_authenticated(self):
"""Verify the root path redirects, authenticated."""
user = baker.make(User)
self.client.force_login(user=user)
result = self.client.get("/")
self.assertEqual(result.status_code, 302)

def test_no_robots(self):
"""Verify robots.txt returns 200"""
result = self.client.get("/robots.txt")
self.assertEqual(result.status_code, 200)


class MySubmissionsViewTests(TestCase):
def setUp(self):
self.user = baker.make(User)
Expand Down
6 changes: 4 additions & 2 deletions backend/audit/viewlib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from .home import Home
from .no_robots import no_robots
from .submission_progress_view import ( # noqa
SubmissionProgressView,
submission_progress_check,
)
from .tribal_data_consent import TribalDataConsent

from .upload_report_view import UploadReportView

from .unlock_after_certification import UnlockAfterCertificationView

# In case we want to iterate through all the views for some reason:
views = [
Home,
SubmissionProgressView,
TribalDataConsent,
UnlockAfterCertificationView,
UploadReportView,
no_robots,
]
21 changes: 21 additions & 0 deletions backend/audit/viewlib/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.views import generic
from django.shortcuts import render, redirect
from django.urls import reverse


# class based views for posts
class Home(generic.View):
"""
This is for the root path: /
It will return the home template if not authenticated and the audit table if
authenticated.
"""

def get(self, request, *args, **kwargs):
if request.user.is_authenticated:
url = reverse("audit:MySubmissions")
return redirect(url)
template_name = "home.html"
extra_context = {}
return render(request, template_name, extra_context)
9 changes: 9 additions & 0 deletions backend/audit/viewlib/no_robots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.http import HttpResponse


def no_robots(_context):
"""
Return Disallow for *
"""
content = "User-agent: *\nDisallow: /"
return HttpResponse(content, content_type="text/plain")
2 changes: 2 additions & 0 deletions backend/audit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@
validate_secondary_auditors_json,
)
from audit.viewlib import ( # noqa
Home,
TribalDataConsent,
SubmissionProgressView,
UnlockAfterCertificationView,
UploadReportView,
no_robots,
submission_progress_check,
)

Expand Down
4 changes: 4 additions & 0 deletions backend/config/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from api import views
from audit import views as auditviews
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
Expand Down Expand Up @@ -73,6 +74,9 @@
),
path("audit/", include("audit.urls")),
path("dissemination/", include("dissemination.urls")),
# home page & robots.txt
path("", auditviews.Home.as_view(), name="Home"),
path("robots.txt", auditviews.no_robots, name="no_robots"),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

if settings.ENABLE_DEBUG_TOOLBAR:
Expand Down

0 comments on commit 7b01951

Please sign in to comment.