Skip to content

Commit

Permalink
Adds endpoint for fetching valid enum choices (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
djperrefort authored Nov 14, 2024
1 parent 8695d43 commit 85a549b
Show file tree
Hide file tree
Showing 17 changed files with 423 additions and 118 deletions.
131 changes: 93 additions & 38 deletions docs/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,43 @@ info:
version: 0.0.0
description: A REST API for managing user resource allocations on HPC systems.
paths:
/allocations/allocation-request/status-choices/:
get:
operationId: allocations_allocation_request_status_choices_retrieve
description: Return valid values for the allocation review `status` field.
tags:
- allocations
security:
- cookieAuth: []
- basicAuth: []
responses:
'200':
content:
application/json:
schema:
PD: Pending
AP: Approved
DC: Declined
CR: Changes Requested
description: ''
/allocations/allocation-review/status-choices/:
get:
operationId: allocations_allocation_review_status_choices_retrieve
description: Return valid values for the allocation review `status` field.
tags:
- allocations
security:
- cookieAuth: []
- basicAuth: []
responses:
'200':
content:
application/json:
schema:
AP: Approved
DC: Declined
CR: Changes Requested
description: ''
/allocations/allocations/:
get:
operationId: allocations_allocations_list
Expand Down Expand Up @@ -1636,24 +1673,24 @@ paths:
schema:
type: array
items:
$ref: '#/components/schemas/AllocationRequestReview'
$ref: '#/components/schemas/AllocationReview'
description: ''
post:
operationId: allocations_reviews_create
description: Create a new `AllocationRequestReview` object.
description: Create a new `AllocationReview` object.
tags:
- allocations
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/AllocationRequestReview'
$ref: '#/components/schemas/AllocationReview'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/AllocationRequestReview'
$ref: '#/components/schemas/AllocationReview'
multipart/form-data:
schema:
$ref: '#/components/schemas/AllocationRequestReview'
$ref: '#/components/schemas/AllocationReview'
required: true
security:
- cookieAuth: []
Expand All @@ -1663,7 +1700,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/AllocationRequestReview'
$ref: '#/components/schemas/AllocationReview'
description: ''
/allocations/reviews/{id}/:
get:
Expand All @@ -1674,7 +1711,7 @@ paths:
name: id
schema:
type: integer
description: A unique integer value identifying this allocation request review.
description: A unique integer value identifying this allocation review.
required: true
tags:
- allocations
Expand All @@ -1686,7 +1723,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/AllocationRequestReview'
$ref: '#/components/schemas/AllocationReview'
description: ''
put:
operationId: allocations_reviews_update
Expand All @@ -1696,21 +1733,21 @@ paths:
name: id
schema:
type: integer
description: A unique integer value identifying this allocation request review.
description: A unique integer value identifying this allocation review.
required: true
tags:
- allocations
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/AllocationRequestReview'
$ref: '#/components/schemas/AllocationReview'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/AllocationRequestReview'
$ref: '#/components/schemas/AllocationReview'
multipart/form-data:
schema:
$ref: '#/components/schemas/AllocationRequestReview'
$ref: '#/components/schemas/AllocationReview'
required: true
security:
- cookieAuth: []
Expand All @@ -1720,7 +1757,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/AllocationRequestReview'
$ref: '#/components/schemas/AllocationReview'
description: ''
patch:
operationId: allocations_reviews_partial_update
Expand All @@ -1730,21 +1767,21 @@ paths:
name: id
schema:
type: integer
description: A unique integer value identifying this allocation request review.
description: A unique integer value identifying this allocation review.
required: true
tags:
- allocations
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchedAllocationRequestReview'
$ref: '#/components/schemas/PatchedAllocationReview'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/PatchedAllocationRequestReview'
$ref: '#/components/schemas/PatchedAllocationReview'
multipart/form-data:
schema:
$ref: '#/components/schemas/PatchedAllocationRequestReview'
$ref: '#/components/schemas/PatchedAllocationReview'
security:
- cookieAuth: []
- basicAuth: []
Expand All @@ -1753,7 +1790,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/AllocationRequestReview'
$ref: '#/components/schemas/AllocationReview'
description: ''
delete:
operationId: allocations_reviews_destroy
Expand All @@ -1763,7 +1800,7 @@ paths:
name: id
schema:
type: integer
description: A unique integer value identifying this allocation request review.
description: A unique integer value identifying this allocation review.
required: true
tags:
- allocations
Expand Down Expand Up @@ -4318,6 +4355,24 @@ paths:
responses:
'204':
description: No response body
/users/team-membership/role-choices/:
get:
operationId: users_team_membership_role_choices_retrieve
description: Return valid values for the team membership `role` field.
tags:
- users
security:
- cookieAuth: []
- basicAuth: []
responses:
'200':
content:
application/json:
schema:
OW: Owner
AD: Admin
MB: Member
description: ''
/users/teams/:
get:
operationId: users_teams_list
Expand Down Expand Up @@ -5240,15 +5295,27 @@ components:
- submitted
- team
- title
AllocationRequestReview:
AllocationRequestStatusEnum:
enum:
- PD
- AP
- DC
- CR
type: string
description: |-
* `PD` - Pending
* `AP` - Approved
* `DC` - Declined
* `CR` - Changes Requested
AllocationReview:
type: object
description: Object serializer for the `AllocationRequestReview` class.
description: Object serializer for the `AllocationReview` class.
properties:
id:
type: integer
readOnly: true
status:
$ref: '#/components/schemas/AllocationRequestReviewStatusEnum'
$ref: '#/components/schemas/AllocationReviewStatusEnum'
public_comments:
type: string
nullable: true
Expand All @@ -5271,7 +5338,7 @@ components:
- last_modified
- request
- status
AllocationRequestReviewStatusEnum:
AllocationReviewStatusEnum:
enum:
- AP
- DC
Expand All @@ -5281,18 +5348,6 @@ components:
* `AP` - Approved
* `DC` - Declined
* `CR` - Changes Requested
AllocationRequestStatusEnum:
enum:
- PD
- AP
- DC
- CR
type: string
description: |-
* `PD` - Pending
* `AP` - Approved
* `DC` - Declined
* `CR` - Changes Requested
AppLog:
type: object
description: Object serializer for the `AppLog` class.
Expand Down Expand Up @@ -5506,15 +5561,15 @@ components:
type: array
items:
type: integer
PatchedAllocationRequestReview:
PatchedAllocationReview:
type: object
description: Object serializer for the `AllocationRequestReview` class.
description: Object serializer for the `AllocationReview` class.
properties:
id:
type: integer
readOnly: true
status:
$ref: '#/components/schemas/AllocationRequestReviewStatusEnum'
$ref: '#/components/schemas/AllocationReviewStatusEnum'
public_comments:
type: string
nullable: true
Expand Down
10 changes: 5 additions & 5 deletions keystone_api/apps/allocations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class AllocationInline(admin.TabularInline):
extra = 1


class AllocationRequestReviewInline(admin.StackedInline):
"""Inline admin interface for the `AllocationRequestReview` model."""
class AllocationReviewInline(admin.StackedInline):
"""Inline admin interface for the `AllocationReview` model."""

model = AllocationRequestReview
model = AllocationReview
verbose_name = 'Review'
show_change_link = True
readonly_fields = ('last_modified',)
Expand Down Expand Up @@ -110,7 +110,7 @@ def team(obj: Allocation) -> str:
def reviews(obj: AllocationRequest) -> int:
"""Return the total number of submitted reviews."""

return sum(1 for _ in obj.allocationrequestreview_set.all())
return sum(1 for _ in obj.allocationreview_set.all())

team.admin_order_field = 'team__name'

Expand All @@ -124,7 +124,7 @@ def reviews(obj: AllocationRequest) -> int:
('expire', admin.DateFieldListFilter),
('status', admin.ChoicesFieldListFilter),
]
inlines = [AllocationInline, AllocationRequestReviewInline, AttachmentInline]
inlines = [AllocationInline, AllocationReviewInline, AttachmentInline]


@admin.register(Cluster)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.1.2 on 2024-11-13 17:36

from django.conf import settings
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('allocations', '0010_rename_file_data_attachment_path'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.RenameModel(
old_name='AllocationRequestReview',
new_name='AllocationReview',
),
]
4 changes: 2 additions & 2 deletions keystone_api/apps/allocations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
__all__ = [
'Allocation',
'AllocationRequest',
'AllocationRequestReview',
'AllocationReview',
'Attachment',
'Cluster',
'TeamModelInterface',
Expand Down Expand Up @@ -107,7 +107,7 @@ def __str__(self) -> str: # pragma: nocover
return truncatechars(self.title, 100)


class AllocationRequestReview(TeamModelInterface, models.Model):
class AllocationReview(TeamModelInterface, models.Model):
"""Reviewer feedback for an allocation request."""

class StatusChoices(models.TextChoices):
Expand Down
8 changes: 4 additions & 4 deletions keystone_api/apps/allocations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'AttachmentSerializer',
'AllocationSerializer',
'AllocationRequestSerializer',
'AllocationRequestReviewSerializer',
'AllocationReviewSerializer',
'ClusterSerializer',
]

Expand Down Expand Up @@ -52,13 +52,13 @@ class Meta:
fields = '__all__'


class AllocationRequestReviewSerializer(serializers.ModelSerializer):
"""Object serializer for the `AllocationRequestReview` class."""
class AllocationReviewSerializer(serializers.ModelSerializer):
"""Object serializer for the `AllocationReview` class."""

class Meta:
"""Serializer settings."""

model = AllocationRequestReview
model = AllocationReview
fields = '__all__'
extra_kwargs = {'reviewer': {'required': False}} # Default reviewer value is set by the view class

Expand Down
Loading

0 comments on commit 85a549b

Please sign in to comment.