Skip to content

Commit

Permalink
feat: api to gather draft authors (#8126)
Browse files Browse the repository at this point in the history
* feat: api to gather draft authors

* chore: black
  • Loading branch information
rjsparks authored Oct 30, 2024
1 parent 14a76f9 commit 1ab36cd
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 13 deletions.
1 change: 1 addition & 0 deletions ietf/api/urls_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
url(r"^doc/submitted_to_rpc/$", views_rpc.submitted_to_rpc),
url(r"^doc/rfc/original_stream/$", views_rpc.rfc_original_stream),
url(r"^doc/rfc/authors/$", views_rpc.rfc_authors),
url(r"^doc/draft/authors/$", views_rpc.draft_authors),
url(r"^person/create_demo_person/$", views_rpc.create_demo_person),
url(r"^person/persons_by_email/$", views_rpc.persons_by_email),
url(r"^person/(?P<person_id>[0-9]+)$", views_rpc.rpc_person),
Expand Down
60 changes: 47 additions & 13 deletions ietf/api/views_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _document_source_format(doc):
return "txt"
return "unknown"


@csrf_exempt
@requires_api_token("ietf.api.views_rpc")
def rpc_draft(request, doc_id):
Expand Down Expand Up @@ -113,6 +113,7 @@ def rpc_draft(request, doc_id):
}
)


@csrf_exempt
@requires_api_token("ietf.api.views_rpc")
def drafts_by_names(request):
Expand Down Expand Up @@ -215,14 +216,16 @@ def persons_by_email(request):
return HttpResponseBadRequest()
response = []
for email in Email.objects.filter(address__in=emails).exclude(person__isnull=True):
response.append({
"email": email.address,
"person_pk": email.person.pk,
"name": email.person.name,
"last_name": email.person.last_name(),
"initials": email.person.initials(),
})
return JsonResponse(response,safe=False)
response.append(
{
"email": email.address,
"person_pk": email.person.pk,
"name": email.person.name,
"last_name": email.person.last_name(),
"initials": email.person.initials(),
}
)
return JsonResponse(response, safe=False)


@csrf_exempt
Expand All @@ -236,15 +239,46 @@ def rfc_authors(request):
except json.JSONDecodeError:
return HttpResponseBadRequest()
response = []
for rfc in Document.objects.filter(type="rfc",rfc_number__in=rfc_numbers):
item={"rfc_number": rfc.rfc_number, "authors": []}
for rfc in Document.objects.filter(type="rfc", rfc_number__in=rfc_numbers):
item = {"rfc_number": rfc.rfc_number, "authors": []}
for author in rfc.authors():
item_author=dict()
item_author = dict()
item_author["person_pk"] = author.pk
item_author["name"] = author.name
item_author["last_name"] = author.last_name()
item_author["initials"] = author.initials()
item_author["email_addresses"] = [
address.lower()
for address in author.email_set.values_list("address", flat=True)
]
item["authors"].append(item_author)
response.append(item)
return JsonResponse(response, safe=False)


@csrf_exempt
@requires_api_token("ietf.api.views_rpc")
def draft_authors(request):
"""Gather authors of the RFCs with the given numbers"""
if request.method != "POST":
return HttpResponseNotAllowed(["POST"])
try:
draft_names = json.loads(request.body)
except json.JSONDecodeError:
return HttpResponseBadRequest()
response = []
for draft in Document.objects.filter(type="draft", name__in=draft_names):
item = {"draft_name": draft.name, "authors": []}
for author in draft.authors():
item_author = dict()
item_author["person_pk"] = author.pk
item_author["name"] = author.name
item_author["last_name"] = author.last_name()
item_author["initials"] = author.initials()
item_author["email_addresses"] = [address.lower() for address in author.email_set.values_list("address", flat=True)]
item_author["email_addresses"] = [
address.lower()
for address in author.email_set.values_list("address", flat=True)
]
item["authors"].append(item_author)
response.append(item)
return JsonResponse(response, safe=False)
Expand Down
43 changes: 43 additions & 0 deletions rpcapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,49 @@ paths:
items:
type: string

/doc/draft/authors/:
post:
operationId: get_draft_authors
summary: Gather authors of the drafts with the given names
description: returns a dict mapping draft names to objects describing authors
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
type: string
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
type: object
properties:
draft_name:
type: string
authors:
type: array
items:
type: object
properties:
person_pk:
type: integer
name:
type: string
last_name:
type: string
initials:
type: string
email_addresses:
type: array
items:
type: string

/doc/rfc/original_stream/:
get:
operationId: get_rfc_original_streams
Expand Down

0 comments on commit 1ab36cd

Please sign in to comment.