Skip to content

Commit 5d9d878

Browse files
fix: Show rfc documents via document_main view (ietf-tools#5919)
* fix: Fix friendly_state() for drafts in rfc state * refactor: Change became-rfc to became_rfc for consistency * refactor: Begin handling RFCs separatly in document_main WIP * chore: Hide reviews and conflict reviews for RFCs * chore: Remove irrelevant fields from rfc doc view * chore: Remove unused variables * chore: Remove "Versions" field from document_rfc.html * chore: Hide "Nits" button for RFC documents
1 parent d87ffb6 commit 5d9d878

7 files changed

Lines changed: 638 additions & 194 deletions

File tree

ietf/doc/migrations/0009_move_rfc_docaliases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def forward(apps, schema_editor):
77
"""Point "rfc..." DocAliases at the rfc-type Document
88
9-
Creates a became-rfc RelatedDocument to preserve the connection between the draft and the rfc.
9+
Creates a became_rfc RelatedDocument to preserve the connection between the draft and the rfc.
1010
"""
1111
DocAlias = apps.get_model("doc", "DocAlias")
1212
Document = apps.get_model("doc", "Document")
@@ -22,7 +22,7 @@ def forward(apps, schema_editor):
2222
RelatedDocument.objects.create(
2323
source=aliased_doc,
2424
target=rfc_alias,
25-
relationship_id="became-rfc",
25+
relationship_id="became_rfc",
2626
)
2727
# Now move the alias from the draft to the rfc
2828
rfc_alias.docs.set([rfc])

ietf/doc/models.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,9 @@ def friendly_state(self):
348348
iesg_state_summary = iesg_state_summary + "::"+"::".join(tag.name for tag in iesg_substate)
349349

350350
if state.slug == "rfc":
351-
# todo check this once became-rfc relationships are actually created
352-
rfcs = self.related_that("became-rfc") # should be only one
351+
rfcs = self.related_that_doc("became_rfc") # should be only one
353352
if len(rfcs) > 0:
354-
rfc = rfcs[0]
353+
rfc = rfcs[0].document
355354
return f"Became RFC {rfc.rfc_number} ({rfc.std_level})"
356355
else:
357356
return "Became RFC"
@@ -995,7 +994,7 @@ def pub_date(self):
995994
996995
This is the rfc publication date for RFCs, and the new-revision date for other documents.
997996
"""
998-
if self.get_state_slug() == "rfc":
997+
if self.is_rfc():
999998
# As of Sept 2022, in ietf.sync.rfceditor.update_docs_from_rfc_index() `published_rfc` events are
1000999
# created with a timestamp whose date *in the PST8PDT timezone* is the official publication date
10011000
# assigned by the RFC editor.

ietf/doc/views_doc.py

Lines changed: 147 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ def interesting_doc_relations(doc):
180180
else:
181181
raise TypeError("Expected this method to be called with a Document or DocHistory object")
182182

183-
that_relationships = STATUSCHANGE_RELATIONS + ('conflrev', 'replaces', 'possibly_replaces', 'updates', 'obs')
183+
that_relationships = STATUSCHANGE_RELATIONS + ('conflrev', 'replaces', 'possibly_replaces', 'updates', 'obs', 'became_rfc')
184184

185-
that_doc_relationships = ('replaces', 'possibly_replaces', 'updates', 'obs')
185+
that_doc_relationships = ('replaces', 'possibly_replaces', 'updates', 'obs', 'became_rfc')
186186

187187
# TODO: This returns the relationships in database order, which may not be the order we want to display them in.
188188
interesting_relations_that = cls.objects.filter(target__docs=target, relationship__in=that_relationships).select_related('source')
@@ -240,7 +240,137 @@ def document_main(request, name, rev=None, document_html=False):
240240

241241

242242
# specific document types
243-
if doc.type_id == "draft":
243+
if doc.is_rfc():
244+
split_content = request.COOKIES.get("full_draft", settings.USER_PREFERENCE_DEFAULTS["full_draft"]) == "off"
245+
if request.GET.get('include_text') == "0":
246+
split_content = True
247+
elif request.GET.get('include_text') == "1":
248+
split_content = False
249+
else:
250+
pass
251+
252+
interesting_relations_that, interesting_relations_that_doc = interesting_doc_relations(doc)
253+
254+
can_edit = has_role(request.user, ("Area Director", "Secretariat"))
255+
can_edit_authors = has_role(request.user, ("Secretariat"))
256+
257+
stream_slugs = StreamName.objects.values_list("slug", flat=True)
258+
# For some reason, AnonymousUser has __iter__, but is not iterable,
259+
# which causes problems in the filter() below. Work around this:
260+
if request.user.is_authenticated:
261+
roles = Role.objects.filter(group__acronym__in=stream_slugs, person__user=request.user)
262+
roles = group_features_role_filter(roles, request.user.person, 'docman_roles')
263+
else:
264+
roles = []
265+
266+
can_change_stream = bool(can_edit or roles)
267+
268+
rfc_aliases = [prettify_std_name(a) for a in aliases
269+
if a.startswith("fyi") or a.startswith("std") or a.startswith("bcp")]
270+
271+
file_urls, found_types = build_file_urls(doc)
272+
content = doc.text_or_error() # pyflakes:ignore
273+
content = markup_txt.markup(maybe_split(content, split=split_content))
274+
275+
if not found_types:
276+
content = "This RFC is not currently available online."
277+
split_content = False
278+
elif "txt" not in found_types:
279+
content = "This RFC is not available in plain text format."
280+
split_content = False
281+
282+
# mailing list search archive
283+
search_archive = "www.ietf.org/mail-archive/web/"
284+
if doc.stream_id == "ietf" and group.type_id == "wg" and group.list_archive:
285+
search_archive = group.list_archive
286+
287+
search_archive = quote(search_archive, safe="~")
288+
289+
# status changes
290+
status_changes = []
291+
proposed_status_changes = []
292+
for r in interesting_relations_that.filter(relationship__in=STATUSCHANGE_RELATIONS):
293+
state_slug = r.source.get_state_slug()
294+
if state_slug in ('appr-sent', 'appr-pend'):
295+
status_changes.append(r)
296+
elif state_slug in ('needshep','adrev','iesgeval','defer','appr-pr'):
297+
proposed_status_changes.append(r)
298+
else:
299+
pass
300+
301+
presentations = doc.future_presentations()
302+
303+
augment_docs_and_user_with_user_info([doc], request.user)
304+
305+
exp_comment = doc.latest_event(IanaExpertDocEvent,type="comment")
306+
iana_experts_comment = exp_comment and exp_comment.desc
307+
308+
# Do not show the Auth48 URL in the "Additional URLs" section
309+
additional_urls = doc.documenturl_set.exclude(tag_id='auth48')
310+
311+
html = None
312+
js = None
313+
css = None
314+
diff_revisions = None
315+
simple_diff_revisions = None
316+
if document_html:
317+
diff_revisions=get_diff_revisions(request, name, doc if isinstance(doc,Document) else doc.doc)
318+
simple_diff_revisions = [t[1] for t in diff_revisions if t[0] == doc.name]
319+
simple_diff_revisions.reverse()
320+
if rev and rev != doc.rev:
321+
# No DocHistory was found matching rev - snapshot will be false
322+
# and doc will be a Document object, not a DocHistory
323+
snapshot = True
324+
doc = doc.fake_history_obj(rev)
325+
else:
326+
html = doc.html_body()
327+
if request.COOKIES.get("pagedeps") == "inline":
328+
js = Path(finders.find("ietf/js/document_html.js")).read_text()
329+
css = Path(finders.find("ietf/css/document_html_inline.css")).read_text()
330+
if html:
331+
css += Path(finders.find("ietf/css/document_html_txt.css")).read_text()
332+
333+
# todo replace document_html?
334+
return render(request, "doc/document_rfc.html" if document_html is False else "doc/document_html.html",
335+
dict(doc=doc,
336+
document_html=document_html,
337+
css=css,
338+
js=js,
339+
html=html,
340+
group=group,
341+
top=top,
342+
name=doc.name,
343+
content=content,
344+
split_content=split_content,
345+
revisions=simple_diff_revisions if document_html else revisions,
346+
snapshot=snapshot,
347+
latest_rev=latest_rev,
348+
can_edit=can_edit,
349+
can_edit_authors=can_edit_authors,
350+
can_change_stream=can_change_stream,
351+
rfc_number=doc.rfc_number,
352+
draft_name=doc.name,
353+
updates=interesting_relations_that_doc.filter(relationship="updates"),
354+
updated_by=interesting_relations_that.filter(relationship="updates"),
355+
obsoletes=interesting_relations_that_doc.filter(relationship="obs"),
356+
obsoleted_by=interesting_relations_that.filter(relationship="obs"),
357+
status_changes=status_changes,
358+
proposed_status_changes=proposed_status_changes,
359+
rfc_aliases=rfc_aliases,
360+
has_errata=doc.pk and doc.tags.filter(slug="errata"), # doc.pk == None if using a fake_history_obj
361+
file_urls=file_urls,
362+
additional_urls=additional_urls,
363+
rfc_editor_state=doc.get_state("draft-rfceditor"),
364+
iana_review_state=doc.get_state("draft-iana-review"),
365+
iana_action_state=doc.get_state("draft-iana-action"),
366+
iana_experts_state=doc.get_state("draft-iana-experts"),
367+
iana_experts_comment=iana_experts_comment,
368+
search_archive=search_archive,
369+
presentations=presentations,
370+
diff_revisions=diff_revisions
371+
))
372+
373+
elif doc.type_id == "draft":
244374
split_content = request.COOKIES.get("full_draft", settings.USER_PREFERENCE_DEFAULTS["full_draft"]) == "off"
245375
if request.GET.get('include_text') == "0":
246376
split_content = True
@@ -278,43 +408,13 @@ def document_main(request, name, rev=None, document_html=False):
278408
is_author = request.user.is_authenticated and doc.documentauthor_set.filter(person__user=request.user).exists()
279409
can_view_possibly_replaces = can_edit_replaces or is_author
280410

281-
rfc_number = name[3:] if name.startswith("rfc") else None
282-
draft_name = None
283-
for a in aliases:
284-
if a.startswith("draft"):
285-
draft_name = a
286-
287-
rfc_aliases = [prettify_std_name(a) for a in aliases
288-
if a.startswith("fyi") or a.startswith("std") or a.startswith("bcp")]
289-
290411
latest_revision = None
291412

292-
# Workaround to allow displaying last rev of draft that became rfc as a draft
293-
# This should be unwound when RFCs become their own documents.
294-
if snapshot:
295-
doc.name = doc.doc.name
296-
name = doc.doc.name
297-
else:
298-
name = doc.name
299-
300413
file_urls, found_types = build_file_urls(doc)
301-
if not snapshot and doc.get_state_slug() == "rfc":
302-
# content
303-
content = doc.text_or_error() # pyflakes:ignore
304-
content = markup_txt.markup(maybe_split(content, split=split_content))
305-
306414
content = doc.text_or_error() # pyflakes:ignore
307415
content = markup_txt.markup(maybe_split(content, split=split_content))
308416

309-
if not snapshot and doc.get_state_slug() == "rfc":
310-
if not found_types:
311-
content = "This RFC is not currently available online."
312-
split_content = False
313-
elif "txt" not in found_types:
314-
content = "This RFC is not available in plain text format."
315-
split_content = False
316-
else:
317-
latest_revision = doc.latest_event(NewRevisionDocEvent, type="new_revision")
417+
latest_revision = doc.latest_event(NewRevisionDocEvent, type="new_revision")
318418

319419
# ballot
320420
iesg_ballot_summary = None
@@ -494,7 +594,7 @@ def document_main(request, name, rev=None, document_html=False):
494594

495595
augment_docs_and_user_with_user_info([doc], request.user)
496596

497-
published = doc.latest_event(type="published_rfc")
597+
published = doc.latest_event(type="published_rfc") # todo rethink this now that published_rfc is on rfc
498598
started_iesg_process = doc.latest_event(type="started_iesg_process")
499599

500600
review_assignments = review_assignments_to_list_for_docs([doc]).get(doc.name, [])
@@ -512,12 +612,6 @@ def document_main(request, name, rev=None, document_html=False):
512612
# Do not show the Auth48 URL in the "Additional URLs" section
513613
additional_urls = doc.documenturl_set.exclude(tag_id='auth48')
514614

515-
# Stream description passing test
516-
if doc.stream != None:
517-
stream_desc = doc.stream.desc
518-
else:
519-
stream_desc = "(None)"
520-
521615
html = None
522616
js = None
523617
css = None
@@ -548,12 +642,11 @@ def document_main(request, name, rev=None, document_html=False):
548642
html=html,
549643
group=group,
550644
top=top,
551-
name=name,
645+
name=doc.name,
552646
content=content,
553647
split_content=split_content,
554648
revisions=simple_diff_revisions if document_html else revisions,
555649
snapshot=snapshot,
556-
stream_desc=stream_desc,
557650
latest_revision=latest_revision,
558651
latest_rev=latest_rev,
559652
can_edit=can_edit,
@@ -571,8 +664,7 @@ def document_main(request, name, rev=None, document_html=False):
571664
can_request_review=can_request_review,
572665
can_submit_unsolicited_review_for_teams=can_submit_unsolicited_review_for_teams,
573666

574-
rfc_number=rfc_number,
575-
draft_name=draft_name,
667+
draft_name=doc.name,
576668
telechat=telechat,
577669
iesg_ballot_summary=iesg_ballot_summary,
578670
submission=submission,
@@ -589,7 +681,7 @@ def document_main(request, name, rev=None, document_html=False):
589681
conflict_reviews=conflict_reviews,
590682
status_changes=status_changes,
591683
proposed_status_changes=proposed_status_changes,
592-
rfc_aliases=rfc_aliases,
684+
# rfc_aliases=rfc_aliases,
593685
has_errata=doc.pk and doc.tags.filter(slug="errata"), # doc.pk == None if using a fake_history_obj
594686
published=published,
595687
file_urls=file_urls,
@@ -618,7 +710,7 @@ def document_main(request, name, rev=None, document_html=False):
618710
diff_revisions=diff_revisions
619711
))
620712

621-
if doc.type_id == "charter":
713+
elif doc.type_id == "charter":
622714
content = doc.text_or_error() # pyflakes:ignore
623715
content = markup_txt.markup(content)
624716

@@ -655,7 +747,7 @@ def document_main(request, name, rev=None, document_html=False):
655747
can_manage=can_manage,
656748
))
657749

658-
if doc.type_id == "bofreq":
750+
elif doc.type_id == "bofreq":
659751
content = markdown.markdown(doc.text_or_error())
660752
editors = bofreq_editors(doc)
661753
responsible = bofreq_responsible(doc)
@@ -675,7 +767,7 @@ def document_main(request, name, rev=None, document_html=False):
675767
editor_can_manage=editor_can_manage,
676768
))
677769

678-
if doc.type_id == "conflrev":
770+
elif doc.type_id == "conflrev":
679771
filename = "%s-%s.txt" % (doc.canonical_name(), doc.rev)
680772
pathname = os.path.join(settings.CONFLICT_REVIEW_PATH,filename)
681773

@@ -705,7 +797,7 @@ def document_main(request, name, rev=None, document_html=False):
705797
approved_states=('appr-reqnopub-pend','appr-reqnopub-sent','appr-noprob-pend','appr-noprob-sent'),
706798
))
707799

708-
if doc.type_id == "statchg":
800+
elif doc.type_id == "statchg":
709801
filename = "%s-%s.txt" % (doc.canonical_name(), doc.rev)
710802
pathname = os.path.join(settings.STATUS_CHANGE_PATH,filename)
711803

@@ -739,7 +831,7 @@ def document_main(request, name, rev=None, document_html=False):
739831
sorted_relations=sorted_relations,
740832
))
741833

742-
if doc.type_id in ("slides", "agenda", "minutes", "bluesheets", "procmaterials",):
834+
elif doc.type_id in ("slides", "agenda", "minutes", "bluesheets", "procmaterials",):
743835
can_manage_material = can_manage_materials(request.user, doc.group)
744836
presentations = doc.future_presentations()
745837
if doc.uploaded_filename:
@@ -795,7 +887,7 @@ def document_main(request, name, rev=None, document_html=False):
795887
))
796888

797889

798-
if doc.type_id == "review":
890+
elif doc.type_id == "review":
799891
basename = "{}.txt".format(doc.name)
800892
pathname = os.path.join(doc.get_file_path(), basename)
801893
content = get_unicode_document_content(basename, pathname)
@@ -821,7 +913,7 @@ def document_main(request, name, rev=None, document_html=False):
821913
assignments=assignments,
822914
))
823915

824-
if doc.type_id in ("chatlog", "polls"):
916+
elif doc.type_id in ("chatlog", "polls"):
825917
if isinstance(doc,DocHistory):
826918
session = doc.doc.sessionpresentation_set.last().session
827919
else:
@@ -1084,9 +1176,9 @@ def document_history(request, name):
10841176

10851177
# Get related docs whose history should be linked
10861178
if doc.type_id == "draft":
1087-
related = doc.related_that_doc("became-rfc")
1179+
related = doc.related_that_doc("became_rfc")
10881180
elif doc.type_id == "rfc":
1089-
related = doc.related_that("became-rfc")
1181+
related = doc.related_that("became_rfc")
10901182
else:
10911183
related = []
10921184

ietf/name/fixtures/names.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9919,7 +9919,7 @@
99199919
"used": true
99209920
},
99219921
"model": "name.docrelationshipname",
9922-
"pk": "became-rfc"
9922+
"pk": "became_rfc"
99239923
},
99249924
{
99259925
"fields": {

ietf/name/migrations/0004_rfc_doctype_names.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def forward(apps, schema_editor):
1414

1515
DocRelationshipName = apps.get_model("name", "DocRelationshipName")
1616
DocRelationshipName.objects.get_or_create(
17-
slug="became-rfc",
17+
slug="became_rfc",
1818
name="became RFC",
1919
used=True,
2020
revname="came from draft",

0 commit comments

Comments
 (0)