From e12c45a58524b0d1b1ce939e33c63b974e610a75 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Tue, 20 Feb 2024 15:02:16 -0500 Subject: [PATCH 1/3] fix: Revert "Email authors" link for RFCs to the draft that it came from (#6856) --- ietf/doc/templatetags/ietf_filters.py | 13 ++++++++++++- ietf/doc/tests.py | 21 ++++++++++++++++++++- ietf/templates/doc/document_draft.html | 16 +++++++++------- ietf/templates/doc/document_rfc.html | 16 +++++++++------- 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/ietf/doc/templatetags/ietf_filters.py b/ietf/doc/templatetags/ietf_filters.py index cfed7aa1db..9c472397b6 100644 --- a/ietf/doc/templatetags/ietf_filters.py +++ b/ietf/doc/templatetags/ietf_filters.py @@ -1,4 +1,4 @@ -# Copyright The IETF Trust 2007-2023, All Rights Reserved +# Copyright The IETF Trust 2007-2024, All Rights Reserved # -*- coding: utf-8 -*- @@ -139,6 +139,17 @@ def rfceditor_info_url(rfcnum : str): return urljoin(settings.RFC_EDITOR_INFO_BASE_URL, f'rfc{rfcnum}') +@register.filter +def mailto_name(doc): + """Return a document name that can be a mailto target, but only if + generate_draft_aliases would have emitted that alias. + """ + if doc.type_id == 'rfc': + draft = doc.came_from_draft() + return draft.name if draft else None + return doc.name + + def doc_name(name): """Check whether a given document exists, and return its canonical name""" diff --git a/ietf/doc/tests.py b/ietf/doc/tests.py index 63953876aa..b850412a70 100644 --- a/ietf/doc/tests.py +++ b/ietf/doc/tests.py @@ -1,4 +1,4 @@ -# Copyright The IETF Trust 2012-2023, All Rights Reserved +# Copyright The IETF Trust 2012-2024, All Rights Reserved # -*- coding: utf-8 -*- @@ -1513,6 +1513,25 @@ def test_draft_group_link(self): self.assertEqual(r.status_code, 200) self.assert_correct_non_wg_group_link(r, group) + def test_document_email_authors_button(self): + # rfc not from draft + rfc = WgRfcFactory() + DocEventFactory.create(doc=rfc, type='published_rfc') + url = urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=rfc.name)) + r = self.client.get(url) + self.assertEqual(r.status_code, 200) + q = PyQuery(r.content) + self.assertEqual(len(q('a:contains("Email authors")')), 0, 'Did not expect "Email authors" button') + + # rfc from draft + draft = WgDraftFactory(group=rfc.group) + draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc) + draft.set_state(State.objects.get(used=True, type="draft", slug="rfc")) + r = self.client.get(url) + self.assertEqual(r.status_code, 200) + q = PyQuery(r.content) + self.assertEqual(len(q('a:contains("Email authors")')), 1, 'Expected "Email authors" button') + def test_document_primary_and_history_views(self): IndividualDraftFactory(name='draft-imaginary-independent-submission') ConflictReviewFactory(name='conflict-review-imaginary-irtf-submission') diff --git a/ietf/templates/doc/document_draft.html b/ietf/templates/doc/document_draft.html index ccfb23f06a..23298ff5df 100644 --- a/ietf/templates/doc/document_draft.html +++ b/ietf/templates/doc/document_draft.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{# Copyright The IETF Trust 2016-2023, All Rights Reserved #} +{# Copyright The IETF Trust 2016-2024, All Rights Reserved #} {% load origin %} {% load static %} {% load ietf_filters %} @@ -610,12 +610,14 @@ {% endif %}
- - - - Email authors - + {% with doc_name=doc|mailto_name %}{% if doc_name %} + + + + Email authors + + {% endif %}{% endwith %} {% if doc.group.type.slug == 'wg' or doc.group.type.slug == 'rg' %} diff --git a/ietf/templates/doc/document_rfc.html b/ietf/templates/doc/document_rfc.html index 9e889afaff..55275b209d 100644 --- a/ietf/templates/doc/document_rfc.html +++ b/ietf/templates/doc/document_rfc.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{# Copyright The IETF Trust 2016-2023, All Rights Reserved #} +{# Copyright The IETF Trust 2016-2024, All Rights Reserved #} {% load origin %} {% load static %} {% load ietf_filters %} @@ -81,12 +81,14 @@ {% endif %}
- - - - Email authors - + {% with doc_name=doc|mailto_name %}{% if doc_name %} + + + + Email authors + + {% endif %}{% endwith %} {% if doc.group.type_id == "wg" or doc.group.type_id == "rg" %} From f9f85545759bf8185ac3ea002b176ab967a14449 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Wed, 21 Feb 2024 16:36:23 -0500 Subject: [PATCH 2/3] refactor: Move mailto_name calculation to the view --- ietf/doc/templatetags/ietf_filters.py | 13 +------------ ietf/doc/views_doc.py | 6 +++++- ietf/templates/doc/document_draft.html | 16 +++++++--------- ietf/templates/doc/document_rfc.html | 6 +++--- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/ietf/doc/templatetags/ietf_filters.py b/ietf/doc/templatetags/ietf_filters.py index 9c472397b6..cfed7aa1db 100644 --- a/ietf/doc/templatetags/ietf_filters.py +++ b/ietf/doc/templatetags/ietf_filters.py @@ -1,4 +1,4 @@ -# Copyright The IETF Trust 2007-2024, All Rights Reserved +# Copyright The IETF Trust 2007-2023, All Rights Reserved # -*- coding: utf-8 -*- @@ -139,17 +139,6 @@ def rfceditor_info_url(rfcnum : str): return urljoin(settings.RFC_EDITOR_INFO_BASE_URL, f'rfc{rfcnum}') -@register.filter -def mailto_name(doc): - """Return a document name that can be a mailto target, but only if - generate_draft_aliases would have emitted that alias. - """ - if doc.type_id == 'rfc': - draft = doc.came_from_draft() - return draft.name if draft else None - return doc.name - - def doc_name(name): """Check whether a given document exists, and return its canonical name""" diff --git a/ietf/doc/views_doc.py b/ietf/doc/views_doc.py index 64f9de4f58..8665d1f9ce 100644 --- a/ietf/doc/views_doc.py +++ b/ietf/doc/views_doc.py @@ -324,6 +324,9 @@ def document_main(request, name, rev=None, document_html=False): submission = group.acronym submission = '%s' % (group.about_url(), submission) + draft = doc.came_from_draft() + mailto_name = draft.name if draft else None + return render(request, "doc/document_rfc.html" if document_html is False else "doc/document_html.html", dict(doc=doc, document_html=document_html, @@ -356,7 +359,8 @@ def document_main(request, name, rev=None, document_html=False): iana_experts_comment=iana_experts_comment, presentations=presentations, diff_revisions=diff_revisions, - submission=submission + submission=submission, + mailto_name=mailto_name, )) elif doc.type_id == "draft": diff --git a/ietf/templates/doc/document_draft.html b/ietf/templates/doc/document_draft.html index 23298ff5df..6afbe476ac 100644 --- a/ietf/templates/doc/document_draft.html +++ b/ietf/templates/doc/document_draft.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{# Copyright The IETF Trust 2016-2024, All Rights Reserved #} +{# Copyright The IETF Trust 2016-2023, All Rights Reserved #} {% load origin %} {% load static %} {% load ietf_filters %} @@ -610,14 +610,12 @@ {% endif %}