Skip to content

Commit

Permalink
feat: support for building rfc authors (#7983)
Browse files Browse the repository at this point in the history
* feat: support for building rfc authors

* chore: copyrights
  • Loading branch information
rjsparks authored Oct 28, 2024
1 parent bc8d3f8 commit 9cf8f10
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ietf/api/urls_rpc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright The IETF Trust 2023, All Rights Reserved
# Copyright The IETF Trust 2023-2024, All Rights Reserved

from ietf.api import views_rpc

Expand All @@ -10,7 +10,9 @@
url(r"^doc/drafts_by_names/", views_rpc.drafts_by_names),
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"^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),
url(r"^persons/$", views_rpc.rpc_persons),
url(r"^subject/(?P<subject_id>[0-9]+)/person/$", views_rpc.rpc_subject_person),
Expand Down
51 changes: 49 additions & 2 deletions ietf/api/views_rpc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright The IETF Trust 2023, All Rights Reserved
# Copyright The IETF Trust 2023-2024, All Rights Reserved

from collections import defaultdict
import json

from django.db.models import OuterRef, Subquery, Q
Expand All @@ -18,7 +19,7 @@
from ietf.doc.factories import WgDraftFactory # DO NOT MERGE INTO MAIN
from ietf.doc.models import Document, DocHistory
from ietf.person.factories import PersonFactory # DO NOT MERGE INTO MAIN
from ietf.person.models import Person
from ietf.person.models import Email, Person


@csrf_exempt
Expand Down Expand Up @@ -203,6 +204,52 @@ def rfc_original_stream(request):
return JsonResponse(response)


@csrf_exempt
@requires_api_token("ietf.api.views_rpc")
def persons_by_email(request):
if request.method != "POST":
return HttpResponseNotAllowed(["POST"])
try:
emails = json.loads(request.body)
except json.JSONDecodeError:
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)


@csrf_exempt
@requires_api_token("ietf.api.views_rpc")
def rfc_authors(request):
"""Gather authors of the RFCs with the given numbers"""
if request.method != "POST":
return HttpResponseNotAllowed(["POST"])
try:
rfc_numbers = json.loads(request.body)
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 author in rfc.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["authors"].append(item_author)
response.append(item)
return JsonResponse(response, safe=False)


@csrf_exempt
@requires_api_token("ietf.api.views_rpc")
def create_demo_person(request):
Expand Down
78 changes: 78 additions & 0 deletions rpcapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,41 @@ paths:
'404':
description: Not found

/person/persons_by_email/:
post:
operationId: persons_by_email
summary: Get a batch of persons by email addresses
description: returns a list of objects with the email address and related person information
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:
email:
type: string
person_pk:
type: integer
name:
type: string
last_name:
type: string
initials:
type: string


/persons/:
post:
operationId: get_persons
Expand Down Expand Up @@ -174,6 +209,49 @@ paths:
additionalProperties:
$ref:'#/components/schemas/Draft'

/doc/rfc/authors/:
post:
operationId: get_rfc_authors
summary: Gather authors of the RFCs with the given numbers
description: returns a dict mapping rfc numbers to objects describing authors
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
type: integer
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
type: object
properties:
rfc_number:
type: integer
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 9cf8f10

Please sign in to comment.