Skip to content

Commit

Permalink
fix: show htmlized views of draft revisions without DocHistory (#5599)
Browse files Browse the repository at this point in the history
* fix: show htmlized views of draft revisions without DocHistory

* fix: handle htmlized views of rfcs corectly
  • Loading branch information
rjsparks authored May 11, 2023
1 parent 2590ab2 commit 1afdb0b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
5 changes: 4 additions & 1 deletion ietf/doc/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,9 @@ def setUp(self):
f.write(self.draft_text)

def test_document_draft(self):
draft = WgDraftFactory(name='draft-ietf-mars-test',rev='01')
draft = WgDraftFactory(name='draft-ietf-mars-test',rev='01', create_revisions=range(0,2))


HolderIprDisclosureFactory(docs=[draft])

# Docs for testing relationships. Does not test 'possibly-replaces'. The 'replaced_by' direction
Expand Down Expand Up @@ -785,6 +787,7 @@ def test_document_draft(self):
self.assertEqual(len(q('#sidebar option[value="draft-ietf-mars-test-00"][selected="selected"]')), 1)

rfc = WgRfcFactory()
rfc.save_with_history([DocEventFactory(doc=rfc)])
(Path(settings.RFC_PATH) / rfc.get_base_name()).touch()
r = self.client.get(urlreverse("ietf.doc.views_doc.document_html", kwargs=dict(name=rfc.canonical_name())))
self.assertEqual(r.status_code, 200)
Expand Down
34 changes: 23 additions & 11 deletions ietf/doc/views_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def document_main(request, name, rev=None, document_html=False):
is_author = request.user.is_authenticated and doc.documentauthor_set.filter(person__user=request.user).exists()
can_view_possibly_replaces = can_edit_replaces or is_author

rfc_number = name[3:] if name.startswith("") else None
rfc_number = name[3:] if name.startswith("rfc") else None
draft_name = None
for a in aliases:
if a.startswith("draft"):
Expand Down Expand Up @@ -487,13 +487,25 @@ def document_main(request, name, rev=None, document_html=False):
html = None
js = None
css = None
diff_revisions = None
simple_diff_revisions = None
if document_html:
html = doc.html_body()
if request.COOKIES.get("pagedeps") == "inline":
js = Path(finders.find("ietf/js/document_html.js")).read_text()
css = Path(finders.find("ietf/css/document_html_inline.css")).read_text()
if html:
css += Path(finders.find("ietf/css/document_html_txt.css")).read_text()
diff_revisions=get_diff_revisions(request, name, doc if isinstance(doc,Document) else doc.doc)
simple_diff_revisions = [t[1] for t in diff_revisions]
simple_diff_revisions.reverse()
if not doc.is_rfc() and rev != doc.rev:
# No DocHistory was found matching rev - snapshot will be false
# and doc will be a Document object, not a DocHistory
snapshot = True
doc = doc.fake_history_obj(rev)
else:
html = doc.html_body()
if request.COOKIES.get("pagedeps") == "inline":
js = Path(finders.find("ietf/js/document_html.js")).read_text()
css = Path(finders.find("ietf/css/document_html_inline.css")).read_text()
if html:
css += Path(finders.find("ietf/css/document_html_txt.css")).read_text()

return render(request, "doc/document_draft.html" if document_html is False else "doc/document_html.html",
dict(doc=doc,
document_html=document_html,
Expand All @@ -505,7 +517,7 @@ def document_main(request, name, rev=None, document_html=False):
name=name,
content=content,
split_content=split_content,
revisions=revisions,
revisions=simple_diff_revisions if document_html else revisions,
snapshot=snapshot,
stream_desc=stream_desc,
latest_revision=latest_revision,
Expand Down Expand Up @@ -544,7 +556,7 @@ def document_main(request, name, rev=None, document_html=False):
status_changes=status_changes,
proposed_status_changes=proposed_status_changes,
rfc_aliases=rfc_aliases,
has_errata=doc.tags.filter(slug="errata"),
has_errata=doc.pk and doc.tags.filter(slug="errata"), # doc.pk == None if using a fake_history_obj
published=published,
file_urls=file_urls,
additional_urls=additional_urls,
Expand All @@ -569,7 +581,7 @@ def document_main(request, name, rev=None, document_html=False):
review_assignments=review_assignments,
no_review_from_teams=no_review_from_teams,
due_date=due_date,
diff_revisions=get_diff_revisions(request, name, doc if isinstance(doc,Document) else doc.doc) if document_html else None
diff_revisions=diff_revisions
))

if doc.type_id == "charter":
Expand Down Expand Up @@ -859,7 +871,7 @@ def document_html(request, name, rev=None):
if not os.path.exists(doc.get_file_name()):
raise Http404("File not found: %s" % doc.get_file_name())

return document_main(request, name=doc.name, rev=doc.rev if not doc.is_rfc() else None, document_html=True)
return document_main(request, name=doc.canonical_name(), rev=doc.rev if not doc.is_rfc() else None, document_html=True)

def document_pdfized(request, name, rev=None, ext=None):

Expand Down

0 comments on commit 1afdb0b

Please sign in to comment.