Skip to content

Commit 8f04d36

Browse files
committed
UPdated Swagger Docs for objects_draft_publish
Changes to be committed: modified: api/scripts/method_specific/POST_api_objects_drafts_publish.py modified: api/views.py
1 parent c7724db commit 8f04d36

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

api/scripts/method_specific/POST_api_objects_drafts_publish.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from django.contrib.auth.models import Group
1111
from django.utils import timezone
1212
from guardian.shortcuts import get_perms
13-
from rest_framework import status
13+
from rest_framework import status, authtoken
1414
from rest_framework.response import Response
15-
15+
from authentication.selectors import get_user_from_auth_token
1616

1717
def post_api_objects_drafts_publish(request):
1818
"""Publish draft
@@ -37,13 +37,29 @@ def post_api_objects_drafts_publish(request):
3737
returning = []
3838
any_failed = False
3939
db_utils = DbUtils.DbUtils()
40-
user = UserUtils.UserUtils().user_from_request(request=request)
40+
41+
try:
42+
user = UserUtils.UserUtils().user_from_request(request=request)
43+
except authtoken.models.Token.DoesNotExist:
44+
user = get_user_from_auth_token(request.META.get("HTTP_AUTHORIZATION").split(" ")[1])
4145
prefix_perms = UserUtils.UserUtils().prefix_perms_for_user(
4246
flatten=True, user_object=user
4347
)
44-
bulk_request = request.data["POST_api_objects_drafts_publish"]
48+
try:
49+
bulk_request = request.data["POST_api_objects_drafts_publish"]
50+
except:
51+
return Response(status=status.HTTP_400_BAD_REQUEST, data={"Request format not accepted."})
4552

4653
for publish_object in bulk_request:
54+
if "draft_id" not in publish_object:
55+
returning.append(
56+
db_utils.messages(parameters={})[
57+
"400_bad_request"
58+
]
59+
)
60+
any_failed = True
61+
continue
62+
4763
draft_exists = BCO.objects.filter(
4864
object_id=publish_object["draft_id"], state="DRAFT"
4965
).exists()

api/views.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
# For helper functions
8080
from api.scripts.utilities import UserUtils
8181

82+
from authentication.services import CustomJSONWebTokenAuthentication
8283

8384
################################################################################################
8485
# NOTES
@@ -800,22 +801,39 @@ def post(self, request) -> Response:
800801
# TODO: What is the difference between this and ApiObjectsPublish?
801802
class ApiObjectsDraftsPublish(APIView):
802803
"""
803-
Publish a BCO
804+
Bulk Publish BCOs
804805
805806
--------------------
807+
808+
Publish draft BCO objects. Once published, a BCO object becomes immutable.
809+
The `object_id` field is optional, and is used to specify if the object
810+
should be published as a specific version, instead of the next available numeric
811+
version.
812+
806813
807-
Publish a draft BCO object. Once published, a BCO object becomes immutable.
814+
```json
815+
{
816+
"POST_api_objects_drafts_publish": [
817+
{
818+
"prefix": "TEST",
819+
"draft_id": "http://127.0.0.1:8000/TEST_000001",
820+
"object_id": "http://127.0.0.1:8000/TEST_000001/1.0",
821+
"delete_draft": false
822+
}
823+
]
824+
}
808825
"""
809826

810827
# TODO: This seems to be missing group, which I would expect to be part of the publication
811828
permission_classes = [IsAuthenticated]
829+
authentication_classes = [CustomJSONWebTokenAuthentication]
812830

813831
POST_api_objects_drafts_publish_schema = openapi.Schema(
814832
type=openapi.TYPE_OBJECT,
815833
required=["draft_id", "prefix"],
816834
properties={
817835
"prefix": openapi.Schema(
818-
type=openapi.TYPE_STRING, description="BCO Prefix to publish with."
836+
type=openapi.TYPE_STRING, description="BCO Prefix to publish with."
819837
),
820838
"draft_id": openapi.Schema(
821839
type=openapi.TYPE_STRING, description="BCO Object Draft ID."
@@ -847,13 +865,14 @@ class ApiObjectsDraftsPublish(APIView):
847865
@swagger_auto_schema(
848866
request_body=request_body,
849867
responses={
850-
200: "BCO Publication is successful.",
851-
300: "Some requests failed.",
868+
200: "All BCO publications successful.",
869+
207: "Some or all publications failed.",
852870
400: "Bad request.",
853-
403: "Invalid token.",
871+
403: "Authentication credentials were not provided.",
854872
},
855873
tags=["BCO Management"],
856874
)
875+
857876
def post(self, request) -> Response:
858877
return check_post_and_process(request, post_api_objects_drafts_publish)
859878

0 commit comments

Comments
 (0)