From 58f2efdb1429f09831b369bbd57b315ba2bfa88f Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Fri, 27 Sep 2024 15:35:54 -0500 Subject: [PATCH 1/2] feat: support for building rfc authors --- ietf/api/urls_rpc.py | 2 ++ ietf/api/views_rpc.py | 49 ++++++++++++++++++++++++++- rpcapi.yaml | 78 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) diff --git a/ietf/api/urls_rpc.py b/ietf/api/urls_rpc.py index 314ff8643f..9b6a9d4429 100644 --- a/ietf/api/urls_rpc.py +++ b/ietf/api/urls_rpc.py @@ -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[0-9]+)$", views_rpc.rpc_person), url(r"^persons/$", views_rpc.rpc_persons), url(r"^subject/(?P[0-9]+)/person/$", views_rpc.rpc_subject_person), diff --git a/ietf/api/views_rpc.py b/ietf/api/views_rpc.py index 9247cfbe98..fc935a3706 100644 --- a/ietf/api/views_rpc.py +++ b/ietf/api/views_rpc.py @@ -1,5 +1,6 @@ # Copyright The IETF Trust 2023, All Rights Reserved +from collections import defaultdict import json from django.db.models import OuterRef, Subquery, Q @@ -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 @@ -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): diff --git a/rpcapi.yaml b/rpcapi.yaml index ef92192168..dd1acc31eb 100644 --- a/rpcapi.yaml +++ b/rpcapi.yaml @@ -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 @@ -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 From f4dea7090d2ab68f28ecab275209f6871fc1194a Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Fri, 27 Sep 2024 15:42:17 -0500 Subject: [PATCH 2/2] chore: copyrights --- ietf/api/urls_rpc.py | 2 +- ietf/api/views_rpc.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ietf/api/urls_rpc.py b/ietf/api/urls_rpc.py index 9b6a9d4429..85783bbc3f 100644 --- a/ietf/api/urls_rpc.py +++ b/ietf/api/urls_rpc.py @@ -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 diff --git a/ietf/api/views_rpc.py b/ietf/api/views_rpc.py index fc935a3706..bddc56919c 100644 --- a/ietf/api/views_rpc.py +++ b/ietf/api/views_rpc.py @@ -1,4 +1,4 @@ -# Copyright The IETF Trust 2023, All Rights Reserved +# Copyright The IETF Trust 2023-2024, All Rights Reserved from collections import defaultdict import json