From 9cf8f1015cc692b252ee3761f043df21e9d08afd Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Mon, 28 Oct 2024 14:23:33 -0500 Subject: [PATCH] feat: support for building rfc authors (#7983) * feat: support for building rfc authors * chore: copyrights --- ietf/api/urls_rpc.py | 4 ++- ietf/api/views_rpc.py | 51 ++++++++++++++++++++++++++-- rpcapi.yaml | 78 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 3 deletions(-) diff --git a/ietf/api/urls_rpc.py b/ietf/api/urls_rpc.py index 314ff8643f..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 @@ -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..bddc56919c 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 +# Copyright The IETF Trust 2023-2024, 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