diff --git a/ietf/api/urls_rpc.py b/ietf/api/urls_rpc.py index 85783bbc3f..f0ff26caed 100644 --- a/ietf/api/urls_rpc.py +++ b/ietf/api/urls_rpc.py @@ -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[0-9]+)$", views_rpc.rpc_person), diff --git a/ietf/api/views_rpc.py b/ietf/api/views_rpc.py index bddc56919c..1d7e12df9f 100644 --- a/ietf/api/views_rpc.py +++ b/ietf/api/views_rpc.py @@ -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): @@ -113,6 +113,7 @@ def rpc_draft(request, doc_id): } ) + @csrf_exempt @requires_api_token("ietf.api.views_rpc") def drafts_by_names(request): @@ -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 @@ -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) diff --git a/rpcapi.yaml b/rpcapi.yaml index dd1acc31eb..f0c90f173d 100644 --- a/rpcapi.yaml +++ b/rpcapi.yaml @@ -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