feat: Include previous draft URL in /api/rfcdiff-latest-json (#5172)
This commit is contained in:
parent
d6d1525da2
commit
cedf6a47ab
|
@ -613,6 +613,7 @@ class RfcdiffSupportTests(TestCase):
|
||||||
def do_draft_test(self, name):
|
def do_draft_test(self, name):
|
||||||
draft = IndividualDraftFactory(name=name, rev='00', create_revisions=range(0,13))
|
draft = IndividualDraftFactory(name=name, rev='00', create_revisions=range(0,13))
|
||||||
draft = reload_db_objects(draft)
|
draft = reload_db_objects(draft)
|
||||||
|
prev_draft_rev = f'{(int(draft.rev)-1):02d}'
|
||||||
|
|
||||||
received = self.getJson(dict(name=draft.name))
|
received = self.getJson(dict(name=draft.name))
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -621,7 +622,8 @@ class RfcdiffSupportTests(TestCase):
|
||||||
name=draft.name,
|
name=draft.name,
|
||||||
rev=draft.rev,
|
rev=draft.rev,
|
||||||
content_url=draft.get_href(),
|
content_url=draft.get_href(),
|
||||||
previous=f'{draft.name}-{(int(draft.rev)-1):02d}'
|
previous=f'{draft.name}-{prev_draft_rev}',
|
||||||
|
previous_url= draft.history_set.get(rev=prev_draft_rev).get_href(),
|
||||||
),
|
),
|
||||||
'Incorrect JSON when draft revision not specified',
|
'Incorrect JSON when draft revision not specified',
|
||||||
)
|
)
|
||||||
|
@ -633,19 +635,22 @@ class RfcdiffSupportTests(TestCase):
|
||||||
name=draft.name,
|
name=draft.name,
|
||||||
rev=draft.rev,
|
rev=draft.rev,
|
||||||
content_url=draft.get_href(),
|
content_url=draft.get_href(),
|
||||||
previous=f'{draft.name}-{(int(draft.rev)-1):02d}'
|
previous=f'{draft.name}-{prev_draft_rev}',
|
||||||
|
previous_url= draft.history_set.get(rev=prev_draft_rev).get_href(),
|
||||||
),
|
),
|
||||||
'Incorrect JSON when latest revision specified',
|
'Incorrect JSON when latest revision specified',
|
||||||
)
|
)
|
||||||
|
|
||||||
received = self.getJson(dict(name=draft.name, rev='10'))
|
received = self.getJson(dict(name=draft.name, rev='10'))
|
||||||
|
prev_draft_rev = '09'
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
received,
|
received,
|
||||||
dict(
|
dict(
|
||||||
name=draft.name,
|
name=draft.name,
|
||||||
rev='10',
|
rev='10',
|
||||||
content_url=draft.history_set.get(rev='10').get_href(),
|
content_url=draft.history_set.get(rev='10').get_href(),
|
||||||
previous=f'{draft.name}-09'
|
previous=f'{draft.name}-{prev_draft_rev}',
|
||||||
|
previous_url= draft.history_set.get(rev=prev_draft_rev).get_href(),
|
||||||
),
|
),
|
||||||
'Incorrect JSON when historical revision specified',
|
'Incorrect JSON when historical revision specified',
|
||||||
)
|
)
|
||||||
|
@ -698,6 +703,7 @@ class RfcdiffSupportTests(TestCase):
|
||||||
content_url=rfc.get_href(),
|
content_url=rfc.get_href(),
|
||||||
name=rfc.canonical_name(),
|
name=rfc.canonical_name(),
|
||||||
previous=f'{draft.name}-{draft.rev}',
|
previous=f'{draft.name}-{draft.rev}',
|
||||||
|
previous_url= draft.history_set.get(rev=draft.rev).get_href(),
|
||||||
),
|
),
|
||||||
'Can look up an RFC by number',
|
'Can look up an RFC by number',
|
||||||
)
|
)
|
||||||
|
@ -713,13 +719,15 @@ class RfcdiffSupportTests(TestCase):
|
||||||
self.assertEqual(num_received, received, 'RFC by draft name and no rev gives same result as by number')
|
self.assertEqual(num_received, received, 'RFC by draft name and no rev gives same result as by number')
|
||||||
|
|
||||||
received = self.getJson(dict(name=draft.name, rev='01'))
|
received = self.getJson(dict(name=draft.name, rev='01'))
|
||||||
|
prev_draft_rev = '00'
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
received,
|
received,
|
||||||
dict(
|
dict(
|
||||||
content_url=draft.history_set.get(rev='01').get_href(),
|
content_url=draft.history_set.get(rev='01').get_href(),
|
||||||
name=draft.name,
|
name=draft.name,
|
||||||
rev='01',
|
rev='01',
|
||||||
previous=f'{draft.name}-00',
|
previous=f'{draft.name}-{prev_draft_rev}',
|
||||||
|
previous_url= draft.history_set.get(rev=prev_draft_rev).get_href(),
|
||||||
),
|
),
|
||||||
'RFC by draft name with rev should give draft name, not canonical name'
|
'RFC by draft name with rev should give draft name, not canonical name'
|
||||||
)
|
)
|
||||||
|
@ -758,6 +766,7 @@ class RfcdiffSupportTests(TestCase):
|
||||||
content_url=rfc.get_href(),
|
content_url=rfc.get_href(),
|
||||||
name=rfc.canonical_name(),
|
name=rfc.canonical_name(),
|
||||||
previous=f'{draft.name}-10',
|
previous=f'{draft.name}-10',
|
||||||
|
previous_url= f'{settings.IETF_ID_ARCHIVE_URL}{draft.name}-10.txt',
|
||||||
),
|
),
|
||||||
'RFC by draft name without rev should return canonical RFC name and no rev',
|
'RFC by draft name without rev should return canonical RFC name and no rev',
|
||||||
)
|
)
|
||||||
|
|
|
@ -308,6 +308,23 @@ HAS_TOMBSTONE = [
|
||||||
3616, 3625, 3627, 3630, 3635, 3636, 3637, 3638
|
3616, 3625, 3627, 3630, 3635, 3636, 3637, 3638
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def get_previous_url(name, rev=None):
|
||||||
|
'''Return previous url'''
|
||||||
|
condition, document, history, found_rev = find_doc_for_rfcdiff(name, rev)
|
||||||
|
previous_url = ''
|
||||||
|
if condition in ('historic version', 'current version'):
|
||||||
|
doc = history if history else document
|
||||||
|
if found_rev:
|
||||||
|
doc.is_rfc = lambda: False
|
||||||
|
previous_url = doc.get_href()
|
||||||
|
elif condition == 'version dochistory not found':
|
||||||
|
document.rev = found_rev
|
||||||
|
document.is_rfc = lambda: False
|
||||||
|
previous_url = document.get_href()
|
||||||
|
return previous_url
|
||||||
|
|
||||||
|
|
||||||
def rfcdiff_latest_json(request, name, rev=None):
|
def rfcdiff_latest_json(request, name, rev=None):
|
||||||
response = dict()
|
response = dict()
|
||||||
condition, document, history, found_rev = find_doc_for_rfcdiff(name, rev)
|
condition, document, history, found_rev = find_doc_for_rfcdiff(name, rev)
|
||||||
|
@ -327,6 +344,7 @@ def rfcdiff_latest_json(request, name, rev=None):
|
||||||
if int(doc.rfc_number()) in HAS_TOMBSTONE and prev_rev != '00':
|
if int(doc.rfc_number()) in HAS_TOMBSTONE and prev_rev != '00':
|
||||||
prev_rev = f'{(int(doc.rev)-1):02d}'
|
prev_rev = f'{(int(doc.rev)-1):02d}'
|
||||||
response['previous'] = f'{doc.name}-{prev_rev}'
|
response['previous'] = f'{doc.name}-{prev_rev}'
|
||||||
|
response['previous_url'] = get_previous_url(doc.name, prev_rev)
|
||||||
else:
|
else:
|
||||||
doc.is_rfc = lambda: False
|
doc.is_rfc = lambda: False
|
||||||
response['content_url'] = doc.get_href()
|
response['content_url'] = doc.get_href()
|
||||||
|
@ -337,14 +355,18 @@ def rfcdiff_latest_json(request, name, rev=None):
|
||||||
if replaces_docs:
|
if replaces_docs:
|
||||||
replaces = replaces_docs[0].document
|
replaces = replaces_docs[0].document
|
||||||
response['previous'] = f'{replaces.name}-{replaces.rev}'
|
response['previous'] = f'{replaces.name}-{replaces.rev}'
|
||||||
|
response['previous_url'] = get_previous_url(replaces.name, replaces.rev)
|
||||||
else:
|
else:
|
||||||
match = re.search("-(rfc)?([0-9][0-9][0-9]+)bis(-.*)?$", name)
|
match = re.search("-(rfc)?([0-9][0-9][0-9]+)bis(-.*)?$", name)
|
||||||
if match and match.group(2):
|
if match and match.group(2):
|
||||||
response['previous'] = f'rfc{match.group(2)}'
|
response['previous'] = f'rfc{match.group(2)}'
|
||||||
|
response['previous_url'] = get_previous_url(f'rfc{match.group(2)}')
|
||||||
else:
|
else:
|
||||||
# not sure what to do if non-numeric values come back, so at least log it
|
# not sure what to do if non-numeric values come back, so at least log it
|
||||||
log.assertion('doc.rev.isdigit()')
|
log.assertion('doc.rev.isdigit()')
|
||||||
response['previous'] = f'{doc.name}-{(int(doc.rev)-1):02d}'
|
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)
|
||||||
elif condition == 'version dochistory not found':
|
elif condition == 'version dochistory not found':
|
||||||
response['warning'] = 'History for this version not found - these results are speculation'
|
response['warning'] = 'History for this version not found - these results are speculation'
|
||||||
response['name'] = document.name
|
response['name'] = document.name
|
||||||
|
@ -355,11 +377,14 @@ def rfcdiff_latest_json(request, name, rev=None):
|
||||||
# not sure what to do if non-numeric values come back, so at least log it
|
# not sure what to do if non-numeric values come back, so at least log it
|
||||||
log.assertion('found_rev.isdigit()')
|
log.assertion('found_rev.isdigit()')
|
||||||
if int(found_rev) > 0:
|
if int(found_rev) > 0:
|
||||||
response['previous'] = f'{document.name}-{(int(found_rev)-1):02d}'
|
prev_rev = f'{(int(found_rev)-1):02d}'
|
||||||
|
response['previous'] = f'{document.name}-{prev_rev}'
|
||||||
|
response['previous_url'] = get_previous_url(document.name, prev_rev)
|
||||||
else:
|
else:
|
||||||
match = re.search("-(rfc)?([0-9][0-9][0-9]+)bis(-.*)?$", name)
|
match = re.search("-(rfc)?([0-9][0-9][0-9]+)bis(-.*)?$", name)
|
||||||
if match and match.group(2):
|
if match and match.group(2):
|
||||||
response['previous'] = f'rfc{match.group(2)}'
|
response['previous'] = f'rfc{match.group(2)}'
|
||||||
|
response['previous_url'] = get_previous_url(f'rfc{match.group(2)}')
|
||||||
if not response:
|
if not response:
|
||||||
raise Http404
|
raise Http404
|
||||||
return HttpResponse(json.dumps(response), content_type='application/json')
|
return HttpResponse(json.dumps(response), content_type='application/json')
|
||||||
|
|
Loading…
Reference in a new issue