Skip to content

Commit

Permalink
fix: repaired rfcdiff api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsparks committed Jul 10, 2023
1 parent a1d776c commit b2ebad1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
16 changes: 8 additions & 8 deletions ietf/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,19 +964,19 @@ def test_draft_with_broken_history(self):

def do_rfc_test(self, draft_name):
draft = WgDraftFactory(name=draft_name, create_revisions=range(0,2))
draft.docalias.create(name=f'rfc{self.next_rfc_number():04}')
rfc = WgRfcFactory(group=draft.group, rfc_number=self.next_rfc_number())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.set_state(State.objects.get(type_id='draft',slug='rfc'))
draft.set_state(State.objects.get(type_id='draft-iesg', slug='pub'))
draft = reload_db_objects(draft)
rfc = WgRfcFactory(group=draft.group) # todo link this with its pre-publication draft
draft, rfc = reload_db_objects(draft, rfc)

number = rfc.rfc_number
received = self.getJson(dict(name=number))
self.assertEqual(
received,
dict(
content_url=rfc.get_href(),
name=rfc.canonical_name(),
name=rfc.name,
previous=f'{draft.name}-{draft.rev}',
previous_url= draft.history_set.get(rev=draft.rev).get_href(),
),
Expand Down Expand Up @@ -1016,23 +1016,23 @@ def test_rfc(self):

def test_rfc_with_tombstone(self):
draft = WgDraftFactory(create_revisions=range(0,2))
draft.docalias.create(name='rfc3261') # See views_doc.HAS_TOMBSTONE
rfc = WgRfcFactory(rfc_number=3261,group=draft.group)# See views_doc.HAS_TOMBSTONE
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.set_state(State.objects.get(type_id='draft',slug='rfc'))
draft.set_state(State.objects.get(type_id='draft-iesg', slug='pub'))
draft = reload_db_objects(draft)
rfc = draft

# Some old rfcs had tombstones that shouldn't be used for comparisons
received = self.getJson(dict(name=rfc.canonical_name()))
self.assertTrue(received['previous'].endswith('00'))

def do_rfc_with_broken_history_test(self, draft_name):
draft = WgDraftFactory(rev='10', name=draft_name)
draft.docalias.create(name=f'rfc{self.next_rfc_number():04}')
rfc = WgRfcFactory(group=draft.group, rfc_number=self.next_rfc_number())
draft.relateddocument_set.create(relationship_id="became_rfc", target=rfc.docalias.first())
draft.set_state(State.objects.get(type_id='draft',slug='rfc'))
draft.set_state(State.objects.get(type_id='draft-iesg', slug='pub'))
draft = reload_db_objects(draft)
rfc = draft

received = self.getJson(dict(name=draft.name))
self.assertEqual(
Expand Down
23 changes: 17 additions & 6 deletions ietf/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,28 @@ def get_previous_url(name, rev=None):
def rfcdiff_latest_json(request, name, rev=None):
response = dict()
condition, document, history, found_rev = find_doc_for_rfcdiff(name, rev)

if document.type_id == "rfc":
draft_alias = next(iter(document.related_that('became_rfc')), None)
if condition == 'no such document':
raise Http404
elif condition in ('historic version', 'current version'):
doc = history if history else document
if not found_rev and doc.type_id == "rfc":
response['content_url'] = doc.get_href()
response['name']=doc.canonical_name()
if doc.name != doc.canonical_name():
if doc.type_id == "rfc":
response['content_url'] = doc.get_href()
response['name']=doc.name
if draft_alias:
draft = draft_alias.document
prev_rev = draft.rev
if doc.rfc_number in HAS_TOMBSTONE and prev_rev != '00':
prev_rev = f'{(int(draft.rev)-1):02d}'
response['previous'] = f'{draft.name}-{prev_rev}'
response['previous_url'] = get_previous_url(draft.name, prev_rev)
elif doc.type_id == "draft" and not found_rev and doc.relateddocument_set.filter(relationship_id="became_rfc").exists():
rfc = doc.related_that_doc("became_rfc")[0].document
response['content_url'] = rfc.get_href()
response['name']=rfc.name
prev_rev = doc.rev
if doc.rfc_number in HAS_TOMBSTONE and prev_rev != '00':
if rfc.rfc_number in HAS_TOMBSTONE and prev_rev != '00':
prev_rev = f'{(int(doc.rev)-1):02d}'
response['previous'] = f'{doc.name}-{prev_rev}'
response['previous_url'] = get_previous_url(doc.name, prev_rev)
Expand Down

0 comments on commit b2ebad1

Please sign in to comment.