Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker/configs/settings_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

APP_API_TOKENS = {
"ietf.api.views.rpc_person" : ["devtoken"],
"ietf.api.views.rpc_draft" : ["devtoken"],
"ietf.api.views.submitted_to_rpc" : ["devtoken"],
"ietf.api.views.create_demo_resources" : ["devtoken"], # remove for production!
}
1 change: 1 addition & 0 deletions ietf/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
url(r'^rpc/person/(?P<person_id>[0-9]+)$', api_views.rpc_person),
url(r'^rpc/persons/$', api_views.rpc_persons),
url(r'^rpc/doc/submitted_to_rpc/$', api_views.submitted_to_rpc),
url(r'^rpc/doc/drafts/(?P<doc_id>[0-9]+)$', api_views.rpc_draft),
url(r'^rpc/person/create_demo_person/$', api_views.create_demo_person),
url(r'^rpc/doc/create_demo_draft/$', api_views.create_demo_draft),

Expand Down
45 changes: 36 additions & 9 deletions ietf/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.db.models import Q
from django.http import HttpResponse, Http404, JsonResponse, HttpResponseForbidden
from django.http import (
HttpResponse,
Http404,
JsonResponse,
HttpResponseNotAllowed,
HttpResponseNotFound,
)
from django.shortcuts import render, get_object_or_404
from django.urls import reverse
from django.utils.decorators import method_decorator
Expand Down Expand Up @@ -454,14 +460,38 @@ def rpc_person(request, person_id):
def rpc_persons(request):
""" Get a batch of rpc person names"""
if request.method != "POST":
return HttpResponseForbidden()
return HttpResponseNotAllowed(["POST"])

pks = json.loads(request.body)
response = dict()
for p in Person.objects.filter(pk__in=pks):
response[str(p.pk)] = p.plain_name()
return JsonResponse(response)

@csrf_exempt
@requires_api_token
def rpc_draft(request, doc_id):
if request.method != "GET":
return HttpResponseNotAllowed(["GET"])

try:
d = Document.objects.get(pk=doc_id, type_id="draft")
except Document.DoesNotExist:
return HttpResponseNotFound()
return JsonResponse({
"id": d.pk,
"name": d.name,
"rev": d.rev,
"stream": d.stream.slug,
"title": d.title,
"pages": d.pages,
"authors": [
{
"id": p.pk,
"plain_name": p.plain_name(),
} for p in d.documentauthor_set.all()
]
})

@csrf_exempt
@requires_api_token
Expand All @@ -488,7 +518,7 @@ def create_demo_person(request):

"""
if request.method != "POST":
return HttpResponseForbidden()
return HttpResponseNotAllowed(["POST"])

request_params = json.loads(request.body)
name = request_params["name"]
Expand All @@ -503,21 +533,18 @@ def create_demo_draft(request):

"""
if request.method != "POST":
return HttpResponseForbidden()
return HttpResponseNotAllowed(["POST"])

request_params = json.loads(request.body)
name = request_params.get("name")
rev = request_params.get("rev")
states = request_params.get("states")
stream_id = request_params.get("stream_id", "ietf")
exists = False
doc = None
if not name:
return HttpResponse(status=400, content="Name is required")
doc = Document.objects.filter(name=name).first()
if doc:
exists = True
else:
if not doc:
kwargs = {"name": name, "stream_id": stream_id}
if states:
kwargs["states"] = states
Expand Down
62 changes: 41 additions & 21 deletions rpcapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ paths:
/person/create_demo_person/:
post:
operationId: create_demo_person
summary: Build a datatraker Person for RPC demo purposes
summary: Build a datatracker Person for RPC demo purposes
description: returns a datatracker User id for a person created with the given name
requestBody:
required: true
Expand Down Expand Up @@ -129,25 +129,27 @@ paths:
schema:
$ref: '#/components/schemas/SubmittedToQueue'

# /subject/person{subjectId}:
# get:
# operationId: get_subject_person_by_id
# summary: Find person for a subject by ID
# description: Returns a single person
# parameters:
# - name: subjectId
# in: path
# description: subject ID of person to return
# required: true
# schema:
# type: string
# responses:
# '200':
# description: OK
# content:
# application/json:
# schema:
# $ref: '#/components/schemas/Person'
/doc/drafts/{docId}:
get:
operationId: get_draft_by_id
summary: Get a draft
description: Returns the draft for the requested ID
parameters:
- name: docId
in: path
description: ID of draft to retrieve
required: true
schema:
type: integer
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Draft'
'404':
description: Not found

components:
schemas:
Expand Down Expand Up @@ -178,7 +180,25 @@ components:
submitted:
type: string
format: date

Draft:
type: object
properties:
id:
type: integer
name:
type: string
rev:
type: string
stream:
type: string
title:
type: string
pages:
type: integer
authors:
type: array
items:
$ref: '#/components/schemas/Person'

securitySchemes:
ApiKeyAuth:
Expand Down