From d8192fa70a369ba43eeb92af7550b6f3bfc64c24 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Sun, 3 Nov 2024 12:35:37 +0000 Subject: [PATCH] feat: Use idnits3 for post submission nits check Fixes #8107 --- ietf/doc/tests.py | 18 ++++++++++++++++++ ietf/doc/views_doc.py | 11 ++++++++++- ietf/settings.py | 1 + ietf/templates/doc/document_draft.html | 4 +++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ietf/doc/tests.py b/ietf/doc/tests.py index e3534ba725..2f74959d4b 100644 --- a/ietf/doc/tests.py +++ b/ietf/doc/tests.py @@ -2996,6 +2996,24 @@ def test_raw_id(self): self.should_succeed(dict(name=draft.name, rev='00',ext='txt')) self.should_404(dict(name=draft.name, rev='00',ext='html')) + @override_settings(IDNITS3_BASE_URL="https://example.org/idnits3") + def test_nits_url(self): + draft = WgDraftFactory(name="draft-ietf-moon-test",rev="01", create_revisions=range(0,2)) + + dir = settings.INTERNET_ALL_DRAFTS_ARCHIVE_DIR + (Path(dir) / f"{draft.name}-01.xml").touch() + r = self.client.get(urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=draft.name))) + self.assertContains(r, settings.IDNITS3_BASE_URL) + + @override_settings(IDNITS_BASE_URL="https://example.org/nits") + def test_nits_url_txt_only(self): + draft = WgDraftFactory(name="draft-ietf-moon-test",rev="01", create_revisions=range(0,2)) + + dir = settings.INTERNET_ALL_DRAFTS_ARCHIVE_DIR + (Path(dir) / f"{draft.name}-01.txt").touch() + r = self.client.get(urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=draft.name))) + self.assertContains(r, settings.IDNITS_BASE_URL) + # test_raw_id_rfc intentionally removed # an rfc is no longer a pseudo-version of a draft. diff --git a/ietf/doc/views_doc.py b/ietf/doc/views_doc.py index 50c60aefc5..ad0a41ea4b 100644 --- a/ietf/doc/views_doc.py +++ b/ietf/doc/views_doc.py @@ -615,6 +615,14 @@ def document_main(request, name, rev=None, document_html=False): # Stream description and name passing test stream = ("draft-stream-" + doc.stream.slug) if doc.stream != None else "(None)" + # Nits URL + nits_url = '' + if 'xml' in found_types: + nits_url = f"{settings.IDNITS3_BASE_URL}?url={[fu[1] for fu in file_urls if fu[0] == 'xml'][0]}" + elif 'txt' in found_types: + nits_url = f"{settings.IDNITS_BASE_URL}?url={[fu[1] for fu in file_urls if fu[0] == 'plain text'][0]}" + + html = None js = None css = None @@ -711,7 +719,8 @@ def document_main(request, name, rev=None, document_html=False): review_requests=review_requests, no_review_from_teams=no_review_from_teams, due_date=due_date, - diff_revisions=diff_revisions + diff_revisions=diff_revisions, + nits_url=nits_url )) elif doc.type_id == "charter": diff --git a/ietf/settings.py b/ietf/settings.py index 0c57d87d11..e309e45d5a 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -554,6 +554,7 @@ def skip_unreadable_post(record): IDTRACKER_BASE_URL = "https://datatracker.ietf.org" RFCDIFF_BASE_URL = "https://author-tools.ietf.org/iddiff" IDNITS_BASE_URL = "https://author-tools.ietf.org/api/idnits" +IDNITS3_BASE_URL = "https://author-tools.ietf.org/api/idnits3" IDNITS_SERVICE_URL = "https://author-tools.ietf.org/idnits" # Content security policy configuration (django-csp) diff --git a/ietf/templates/doc/document_draft.html b/ietf/templates/doc/document_draft.html index d5ea074422..3cefe9fca2 100644 --- a/ietf/templates/doc/document_draft.html +++ b/ietf/templates/doc/document_draft.html @@ -653,14 +653,16 @@ Referenced by + {% if nits_url %} Nits + {% endif %}