Skip to content

Commit

Permalink
Adds endpoint for file attachments (#467)
Browse files Browse the repository at this point in the history
* Adds attachment endpoint

* Updates openapi
  • Loading branch information
djperrefort authored Oct 29, 2024
1 parent 1173044 commit 67935e6
Show file tree
Hide file tree
Showing 9 changed files with 576 additions and 3 deletions.
318 changes: 318 additions & 0 deletions docs/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,287 @@ paths:
responses:
'204':
description: No response body
/allocations/attachments/:
get:
operationId: allocations_attachments_list
description: Files submitted as attachments to allocation requests
parameters:
- in: query
name: id
schema:
type: integer
- in: query
name: id__gt
schema:
type: integer
- in: query
name: id__gte
schema:
type: integer
- in: query
name: id__in
schema:
type: array
items:
type: integer
description: Multiple values may be separated by commas.
explode: false
style: form
- in: query
name: id__isnull
schema:
type: boolean
- in: query
name: id__lt
schema:
type: integer
- in: query
name: id__lte
schema:
type: integer
- name: ordering
required: false
in: query
description: Which field to use when ordering the results.
schema:
type: string
- in: query
name: request
schema:
type: integer
- in: query
name: request__in
schema:
type: array
items:
type: integer
description: Multiple values may be separated by commas.
explode: false
style: form
- in: query
name: request__isnull
schema:
type: boolean
- in: query
name: uploaded
schema:
type: string
format: date-time
- in: query
name: uploaded__day
schema:
type: number
- in: query
name: uploaded__gt
schema:
type: string
format: date-time
- in: query
name: uploaded__gte
schema:
type: string
format: date-time
- in: query
name: uploaded__hour
schema:
type: number
- in: query
name: uploaded__in
schema:
type: array
items:
type: string
format: date-time
description: Multiple values may be separated by commas.
explode: false
style: form
- in: query
name: uploaded__isnull
schema:
type: boolean
- in: query
name: uploaded__lt
schema:
type: string
format: date-time
- in: query
name: uploaded__lte
schema:
type: string
format: date-time
- in: query
name: uploaded__minute
schema:
type: number
- in: query
name: uploaded__month
schema:
type: number
- in: query
name: uploaded__second
schema:
type: number
- in: query
name: uploaded__week
schema:
type: number
- in: query
name: uploaded__week_day
schema:
type: number
- in: query
name: uploaded__year
schema:
type: number
tags:
- allocations
security:
- cookieAuth: []
- basicAuth: []
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Attachment'
description: ''
post:
operationId: allocations_attachments_create
description: Files submitted as attachments to allocation requests
tags:
- allocations
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Attachment'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Attachment'
multipart/form-data:
schema:
$ref: '#/components/schemas/Attachment'
required: true
security:
- cookieAuth: []
- basicAuth: []
responses:
'201':
content:
application/json:
schema:
$ref: '#/components/schemas/Attachment'
description: ''
/allocations/attachments/{id}/:
get:
operationId: allocations_attachments_retrieve
description: Files submitted as attachments to allocation requests
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this attachment.
required: true
tags:
- allocations
security:
- cookieAuth: []
- basicAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Attachment'
description: ''
put:
operationId: allocations_attachments_update
description: Files submitted as attachments to allocation requests
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this attachment.
required: true
tags:
- allocations
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Attachment'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Attachment'
multipart/form-data:
schema:
$ref: '#/components/schemas/Attachment'
required: true
security:
- cookieAuth: []
- basicAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Attachment'
description: ''
patch:
operationId: allocations_attachments_partial_update
description: Files submitted as attachments to allocation requests
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this attachment.
required: true
tags:
- allocations
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/PatchedAttachment'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/PatchedAttachment'
multipart/form-data:
schema:
$ref: '#/components/schemas/PatchedAttachment'
security:
- cookieAuth: []
- basicAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Attachment'
description: ''
delete:
operationId: allocations_attachments_destroy
description: Files submitted as attachments to allocation requests
parameters:
- in: path
name: id
schema:
type: integer
description: A unique integer value identifying this attachment.
required: true
tags:
- allocations
security:
- cookieAuth: []
- basicAuth: []
responses:
'204':
description: No response body
/allocations/clusters/:
get:
operationId: allocations_clusters_list
Expand Down Expand Up @@ -5054,6 +5335,27 @@ components:
- name
- pathname
- time
Attachment:
type: object
description: Object serializer for the `Attachment` class.
properties:
id:
type: integer
readOnly: true
path:
type: string
readOnly: true
uploaded:
type: string
format: date-time
readOnly: true
request:
type: integer
required:
- id
- path
- request
- uploaded
Cluster:
type: object
description: Object serializer for the `Cluster` class.
Expand Down Expand Up @@ -5230,6 +5532,22 @@ components:
reviewer:
type: integer
nullable: true
PatchedAttachment:
type: object
description: Object serializer for the `Attachment` class.
properties:
id:
type: integer
readOnly: true
path:
type: string
readOnly: true
uploaded:
type: string
format: date-time
readOnly: true
request:
type: integer
PatchedCluster:
type: object
description: Object serializer for the `Cluster` class.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.1.2 on 2024-10-28 21:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('allocations', '0009_remove_allocationrequest_group'),
]

operations = [
migrations.RenameField(
model_name='attachment',
old_name='file_data',
new_name='path',
),
migrations.AlterField(
model_name='attachment',
name='path',
field=models.FileField(upload_to='allocations'),
),
]
9 changes: 7 additions & 2 deletions keystone_api/apps/allocations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,19 @@ def __str__(self) -> str: # pragma: nocover
return f'{self.reviewer} review for \"{self.request.title}\"'


class Attachment(models.Model):
class Attachment(TeamModelInterface, models.Model):
"""File data uploaded by users."""

file_data = models.FileField()
path = models.FileField(upload_to='allocations')
uploaded = models.DateTimeField(auto_now=True)

request = models.ForeignKey('AllocationRequest', on_delete=models.CASCADE)

def get_team(self) -> Team:
"""Return the user team tied to the current record."""

return self.request.team


class Cluster(models.Model):
"""A slurm cluster and it's associated management settings."""
Expand Down
Loading

0 comments on commit 67935e6

Please sign in to comment.