Skip to content

Commit

Permalink
fix: change rfc/rev and search behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
maybe-hello-world committed Jul 22, 2023
1 parent 36037b7 commit ebc654c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
19 changes: 17 additions & 2 deletions ietf/doc/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ def test_search_for_name(self):
parsed = urlparse(r["Location"])
self.assertEqual(parsed.path, urlreverse('ietf.doc.views_search.search'))
self.assertEqual(parse_qs(parsed.query)["name"][0], "draft-ietf-doesnotexist-42")

def test_search_rfc(self):
rfc = WgRfcFactory(name="rfc0000")

# search for existing RFC should redirect directly to the RFC page
r = self.client.get(urlreverse('ietf.doc.views_search.search_for_name', kwargs=dict(name=rfc.name)))
self.assertRedirects(r, f'/doc/{rfc.name}/', status_code=302, target_status_code=200)

# search for existing RFC with revision number should redirect to the RFC page
r = self.client.get(urlreverse('ietf.doc.views_search.search_for_name', kwargs=dict(name=rfc.name + "-99")), follow=True)
self.assertRedirects(r, f'/doc/{rfc.name}/', status_code=302, target_status_code=200)

def test_frontpage(self):
r = self.client.get("/")
Expand Down Expand Up @@ -1558,9 +1569,9 @@ def test_document_primary_and_history_views(self):
self.assertEqual(r.status_code, 200)
self.assertContains(r, "%s-01"%docname)

# Fetch version number which is too large, that should return 404
# Fetch version number which is too large, that should redirect to main page
r = self.client.get(urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=doc.name,rev="02")))
self.assertEqual(r.status_code, 404)
self.assertEqual(r.status_code, 302)

# Fetch 00 version which should result that version
r = self.client.get(urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=doc.name,rev="00")))
Expand Down Expand Up @@ -1617,6 +1628,10 @@ def test_document_charter(self):
CharterFactory(name='charter-ietf-mars')
r = self.client.get(urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name="charter-ietf-mars")))
self.assertEqual(r.status_code, 200)

def test_incorrect_rfc_url(self):
r = self.client.get(urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name="rfc8989", rev="00")))
self.assertEqual(r.status_code, 404)

def test_document_conflict_review(self):
ConflictReviewFactory(name='conflict-review-imaginary-irtf-submission')
Expand Down
8 changes: 6 additions & 2 deletions ietf/doc/views_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ def interesting_doc_relations(doc):
return interesting_relations_that, interesting_relations_that_doc

def document_main(request, name, rev=None, document_html=False):
if name.startswith("rfc") and rev is not None:
raise Http404()

doc = get_object_or_404(Document.objects.select_related(), docalias__name=name)

# take care of possible redirections
Expand Down Expand Up @@ -218,8 +221,9 @@ def document_main(request, name, rev=None, document_html=False):
snapshot = True
doc = h
break
else:
raise Http404()

if not snapshot and document_html is False:
return redirect('ietf.doc.views_doc.document_main', name=name)

if doc.type_id == "charter":
# find old group, too
Expand Down
4 changes: 2 additions & 2 deletions ietf/doc/views_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ def cached_redirect(cache_key, url):
redirect_to = find_unique(rev_split.group(1))
if redirect_to:
rev = rev_split.group(2)
# check if we can redirect directly to the rev
if DocHistory.objects.filter(doc__docalias__name=redirect_to, rev=rev).exists():
# check if we can redirect directly to the rev if it's draft, if rfc - always redirect to main page
if not redirect_to.startswith('rfc') and DocHistory.objects.filter(doc__docalias__name=redirect_to, rev=rev).exists():
return cached_redirect(cache_key, urlreverse("ietf.doc.views_doc.document_main", kwargs={ "name": redirect_to, "rev": rev }))
else:
return cached_redirect(cache_key, urlreverse("ietf.doc.views_doc.document_main", kwargs={ "name": redirect_to }))
Expand Down

0 comments on commit ebc654c

Please sign in to comment.