Skip to content

Commit 092d862

Browse files
committed
Linting & doc updates for POST_api_prefixes_modify
Changes to be committed: modified: bco_api/api/scripts/method_specific/POST_api_prefixes_modify.py modified: bco_api/api/views.py
1 parent 2c70dac commit 092d862

File tree

2 files changed

+110
-59
lines changed

2 files changed

+110
-59
lines changed

bco_api/api/scripts/method_specific/POST_api_prefixes_modify.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
1-
# For getting objects out of the database.
2-
from api.scripts.utilities import DbUtils
1+
#!/usr/bin/env python3
2+
"""Modify a Prefix
33
4-
# Checking that a user is in a group.
5-
from api.scripts.utilities import UserUtils
4+
Modify a prefix which already exists.
65
7-
# Model fields
6+
The requestor *must* be in the group prefix_admins to modify a prefix.
7+
"""
8+
from api.scripts.utilities import DbUtils
9+
from api.scripts.utilities import UserUtils
810
from api.models import prefixes
9-
10-
# Responses
1111
from rest_framework import status
1212
from rest_framework.response import Response
1313

1414

1515

1616

17-
def POST_api_prefixes_modify(
18-
incoming
19-
):
20-
21-
# Instantiate any necessary imports.
22-
db = DbUtils.DbUtils()
23-
uu = UserUtils.UserUtils()
17+
def POST_api_prefixes_modify(request):
18+
"""Modify a Prefix
2419
25-
# Define the bulk request.
26-
bulk_request = incoming.data['POST_api_prefixes_modify']
20+
Parameters
21+
----------
22+
request: rest_framework.request.Request
23+
Django request object.
2724
28-
# Get all existing prefixes.
25+
Returns
26+
-------
27+
rest_framework.response.Response
28+
An HttpResponse that allows its data to be rendered into
29+
arbitrary media types.
30+
"""
31+
# Instantiate any necessary imports.
32+
db_utils = DbUtils.DbUtils()
33+
user_utils = UserUtils.UserUtils()
34+
35+
bulk_request = request.data['POST_api_prefixes_modify']
2936
available_prefixes = list(
30-
prefixes.objects.all().values_list(
31-
'prefix',
32-
flat = True
33-
)
34-
)
37+
prefixes.objects.all().values_list('prefix', flat = True))
3538

3639
# Construct an array to return information about processing
3740
# the request.
@@ -59,31 +62,31 @@ def POST_api_prefixes_modify(
5962

6063
# Update the request status.
6164
# Bad request.
62-
errors['404_missing_prefix'] = db.messages(
65+
errors['404_missing_prefix'] = db_utils.messages(
6366
parameters = {
6467
'prefix': standardized
6568
}
6669
)['404_missing_prefix']
6770

6871
# Does the user exist?
69-
if uu.check_user_exists(un = creation_object['owner_user']) is False:
72+
if user_utils.check_user_exists(un = creation_object['owner_user']) is False:
7073

7174
error_check = True
7275

7376
# Bad request.
74-
errors['404_user_not_found'] = db.messages(
77+
errors['404_user_not_found'] = db_utils.messages(
7578
parameters = {
7679
'username': creation_object['owner_user']
7780
}
7881
)['404_user_not_found']
7982

8083
# Does the group exist?
81-
if uu.check_group_exists(n = creation_object['owner_group']) is False:
84+
if user_utils.check_group_exists(n = creation_object['owner_group']) is False:
8285

8386
error_check = True
8487

8588
# Bad request.
86-
errors['404_group_not_found'] = db.messages(
89+
errors['404_group_not_found'] = db_utils.messages(
8790
parameters = {
8891
'group': creation_object['owner_group']
8992
}
@@ -92,12 +95,12 @@ def POST_api_prefixes_modify(
9295
# Was the expiration date validly formatted and, if so,
9396
# is it after right now?
9497
if 'expiration_date' in prfx:
95-
if db.check_expiration(dt_string = prfx['expiration_date']) is not None:
98+
if db_utils.check_expiration(dt_string = prfx['expiration_date']) is not None:
9699

97100
error_check = True
98101

99102
# Bad request.
100-
errors['400_invalid_expiration_date'] = db.messages(
103+
errors['400_invalid_expiration_date'] = db_utils.messages(
101104
parameters = {
102105
'expiration_date': prfx['expiration_date']
103106
}
@@ -112,8 +115,8 @@ def POST_api_prefixes_modify(
112115
p_model_name = 'prefixes',
113116
p_fields = ['created_by', 'description', 'owner_group', 'owner_user', 'prefix'],
114117
p_data = {
115-
'created_by': uu.user_from_request(
116-
rq = incoming
118+
'created_by': user_utils.user_from_request(
119+
request = request
117120
).username,
118121
'description': prfx['description'],
119122
'owner_group': creation_object['owner_group'],
@@ -123,7 +126,7 @@ def POST_api_prefixes_modify(
123126
)
124127

125128
# Created the prefix.
126-
errors['201_prefix_modify'] = db.messages(
129+
errors['201_prefix_modify'] = db_utils.messages(
127130
parameters = {
128131
'prefix': standardized
129132
}

bco_api/api/views.py

Lines changed: 75 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -604,26 +604,33 @@ class ApiObjectsDraftsPublish(APIView):
604604
permission_classes = [IsAuthenticated]
605605

606606
POST_api_objects_drafts_publish_schema = openapi.Schema(
607-
type=openapi.TYPE_OBJECT,
608-
required=['draft_id', 'prefix'],
609-
properties={
610-
'prefix' : openapi.Schema(type=openapi.TYPE_STRING, description='BCO Prefix to publish with.'),
611-
'draft_id' : openapi.Schema(type=openapi.TYPE_STRING, description='BCO Object Draft ID.'),
612-
'object_id' : openapi.Schema(type=openapi.TYPE_STRING, description='BCO Object ID.'),
613-
'delete_draft': openapi.Schema(type=openapi.TYPE_BOOLEAN, description='Whether or not to delete the draft. False by default.'),
614-
}
615-
)
607+
type=openapi.TYPE_OBJECT,
608+
required=['draft_id', 'prefix'],
609+
properties={
610+
'prefix': openapi.Schema(type=openapi.TYPE_STRING,
611+
description='BCO Prefix to publish with.'),
612+
'draft_id': openapi.Schema(type=openapi.TYPE_STRING,
613+
description='BCO Object Draft ID.'),
614+
'object_id': openapi.Schema(type=openapi.TYPE_STRING,
615+
description='BCO Object ID.'),
616+
'delete_draft': openapi.Schema(type=openapi.TYPE_BOOLEAN,
617+
description='Whether or not to delete the draft.'
618+
' False by default.'),
619+
}
620+
)
616621

617622
request_body = openapi.Schema(
618623
type=openapi.TYPE_OBJECT,
619624
title="Publish Draft BCO Schema",
620625
description="Parameters that are supported when setting publishing BCOs.",
621626
required=['POST_api_objects_drafts_publish'],
622627
properties={
623-
'POST_api_objects_drafts_publish': openapi.Schema(type=openapi.TYPE_ARRAY,
624-
items=POST_api_objects_drafts_publish_schema,
625-
description='BCO drafts to publish.'),
626-
})
628+
'POST_api_objects_drafts_publish': openapi.Schema(
629+
type=openapi.TYPE_ARRAY,
630+
items=POST_api_objects_drafts_publish_schema,
631+
description='BCO drafts to publish.')
632+
}
633+
)
627634

628635
@swagger_auto_schema(request_body=request_body, responses={
629636
200: "BCO Publication is successful.",
@@ -996,7 +1003,7 @@ class ApiPrefixesModify(APIView):
9961003
9971004
--------------------
9981005
999-
# Modify a prefix which already exists.
1006+
Modify a prefix which already exists.
10001007
10011008
The requestor *must* be in the group prefix_admins to modify a prefix.
10021009
@@ -1015,7 +1022,7 @@ class ApiPrefixesModify(APIView):
10151022
{
10161023
"description": "Just another prefix description here as well.",
10171024
"expiration_date": "2025-01-01-01-01-01",
1018-
"prefix": "othER"
1025+
"prefix": "othER"
10191026
}
10201027
]
10211028
}
@@ -1027,21 +1034,62 @@ class ApiPrefixesModify(APIView):
10271034

10281035
# Permissions - prefix admins only
10291036
permission_classes = [RequestorInPrefixAdminsGroup]
1037+
prefixes_object_schema = openapi.Schema(
1038+
type=openapi.TYPE_OBJECT,
1039+
required=[],
1040+
properties={
1041+
'description': openapi.Schema(
1042+
type=openapi.TYPE_STRING,
1043+
description='A description of what this prefix should'
1044+
' represent. For example, the prefix \'GLY\' would be '
1045+
'related to BCOs which were derived from GlyGen workflows.'
1046+
),
1047+
'expiration_date': openapi.Schema(
1048+
type=openapi.TYPE_STRING,
1049+
description='The datetime at which this prefix expires in the'
1050+
' format YYYY-MM-DD-HH-MM-SS.'),
1051+
'prefix': openapi.Schema(
1052+
type=openapi.TYPE_STRING,
1053+
description='Any prefix which satsifies the naming standard')
1054+
}
1055+
1056+
1057+
)
1058+
POST_api_prefixes_modify_schema = openapi.Schema(
1059+
type=openapi.TYPE_OBJECT,
1060+
required=[],
1061+
properties={
1062+
'owner_group': openapi.Schema(
1063+
type=openapi.TYPE_STRING,
1064+
description='Which group should own the prefix. *The'
1065+
' requestor does not have to be in the owner group to'
1066+
' assign this.*'),
1067+
'owner_user': openapi.Schema(
1068+
type=openapi.TYPE_STRING,
1069+
description='Which user should own the prefix. *The requestor'
1070+
' does not have to be owner_user but owner_user must be in'
1071+
' owner_group*.'),
1072+
'prefixes': openapi.Schema(
1073+
type=openapi.TYPE_ARRAY,
1074+
items=prefixes_object_schema,
1075+
description='Any prefix which satsifies the naming standard')
1076+
}
1077+
)
10301078

10311079
# TODO: Need to get the schema that is being sent here from FE
10321080
request_body = openapi.Schema(
1033-
type=openapi.TYPE_OBJECT,
1034-
title="Prefix Modification Schema",
1035-
description="Several parameters are required to modify a prefix.",
1036-
required=['prefix'],
1037-
properties={
1038-
'description': openapi.Schema(type=openapi.TYPE_STRING, description='A description of what this prefix should represent. For example, the prefix \'GLY\' would be related to BCOs which were derived from GlyGen workflows.'),
1039-
'expiration_date': openapi.Schema(type=openapi.TYPE_STRING, description='The datetime at which this prefix expires in the format YYYY-MM-DD-HH-MM-SS.'),
1040-
'owner_group': openapi.Schema(type=openapi.TYPE_STRING, description='Which group should own the prefix. *The requestor does not have to be in the owner group to assign this.*'),
1041-
'owner_user': openapi.Schema(type=openapi.TYPE_STRING, description='Which user should own the prefix. *The requestor does not have to be owner_user but owner_user must be in owner_group*.'),
1042-
'prefix': openapi.Schema(type=openapi.TYPE_STRING, description='Any prefix which satsifies the naming standard (see link...)'),
1043-
})
1044-
1081+
type=openapi.TYPE_OBJECT,
1082+
title="Prefix Modification Schema",
1083+
description="Several parameters are required to modify a prefix.",
1084+
required=['POST_api_prefixes_modify'],
1085+
properties={
1086+
'POST_api_prefixes_modify': openapi.Schema(
1087+
type=openapi.TYPE_ARRAY,
1088+
items=POST_api_prefixes_modify_schema,
1089+
description=''
1090+
)
1091+
}) # TODO: ADD LINK FOR PREFIX DOCUMENTATION
1092+
10451093
@swagger_auto_schema(request_body=request_body, responses={
10461094
200: "The prefix was successfully modified.",
10471095
400: "Bad request because owner_user and/or owner_group do not exist.",

0 commit comments

Comments
 (0)