Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#45908] API specification: Add prepare upload endpoint

Eric Schuberta19a71e718db
diff --git a/docs/api/apiv3/components/schemas/storage_file_upload_link_model.yml b/docs/api/apiv3/components/schemas/storage_file_upload_link_model.yml
new file mode 100644
index 00000000000..7963feb8781
--- /dev/null
+++ b/docs/api/apiv3/components/schemas/storage_file_upload_link_model.yml
@@ -0,0 +1,32 @@
+# Schema: StorageFileUploadLinkModel
+---
+type: object
+required:
+ - _type
+ - _links
+properties:
+ _type:
+ type: string
+ enum:
+ - UploadLink
+ _links:
+ type: object
+ required:
+ - self
+ - destination
+ properties:
+ self:
+ allOf:
+ - $ref: './link.yml'
+ - description: |-
+ This upload link resource. As the upload link is a temporal object, and cannot be retrieved again, the
+ self link usually is `urn:openproject-org:api:v3:storages:upload_link:no_link_provided`.
+
+ **Resource**: UploadLink
+ destination:
+ allOf:
+ - $ref: './link.yml'
+ - description: |-
+ The direct upload link.
+
+ **Resource**: N/A
diff --git a/docs/api/apiv3/components/schemas/storage_file_upload_preparation_model.yml b/docs/api/apiv3/components/schemas/storage_file_upload_preparation_model.yml
new file mode 100644
index 00000000000..6349cc5325b
--- /dev/null
+++ b/docs/api/apiv3/components/schemas/storage_file_upload_preparation_model.yml
@@ -0,0 +1,20 @@
+# Schema: StorageFileUploadPreparationModel
+---
+type: object
+required:
+ - projectId
+ - fileName
+ - parent
+properties:
+ projectId:
+ type: integer
+ description: The project identifier, from where a user starts uploading a file.
+ minimum: 1
+ fileName:
+ type: string
+ description: The file name.
+ parent:
+ type: string
+ description: |-
+ The directory to which the file is to be uploaded. For root directories, the value `/` must
+ be provided.
diff --git a/docs/api/apiv3/components/schemas/time_entry_create_form.yml b/docs/api/apiv3/components/schemas/time_entry_create_form.yml
deleted file mode 100644
index fe277818188..00000000000
--- a/docs/api/apiv3/components/schemas/time_entry_create_form.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-# Schema: Time_entry_create_form
---- {}
diff --git a/docs/api/apiv3/components/schemas/time_entry_update_form.yml b/docs/api/apiv3/components/schemas/time_entry_update_form.yml
deleted file mode 100644
index de6b33c3f18..00000000000
--- a/docs/api/apiv3/components/schemas/time_entry_update_form.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-# Schema: Time_entry_update_form
---- {}
diff --git a/docs/api/apiv3/components/schemas/unlock_user.yml b/docs/api/apiv3/components/schemas/unlock_user.yml
deleted file mode 100644
index 8dce50d1081..00000000000
--- a/docs/api/apiv3/components/schemas/unlock_user.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-# Schema: Unlock_user
---- {}
diff --git a/docs/api/apiv3/components/schemas/update_group.yml b/docs/api/apiv3/components/schemas/update_group.yml
deleted file mode 100644
index 7d60782ffc3..00000000000
--- a/docs/api/apiv3/components/schemas/update_group.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-# Schema: Update_group
---- {}
diff --git a/docs/api/apiv3/components/schemas/update_user.yml b/docs/api/apiv3/components/schemas/update_user.yml
deleted file mode 100644
index 22dc3272489..00000000000
--- a/docs/api/apiv3/components/schemas/update_user.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-# Schema: Update_User
---- {}
diff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.yml
index 49a2d521d7e..785c56f4d88 100644
--- a/docs/api/apiv3/openapi-spec.yml
+++ b/docs/api/apiv3/openapi-spec.yml
@@ -363,6 +363,8 @@ paths:
"$ref": "./paths/storage.yml"
"/api/v3/storages/{id}/files":
"$ref": "./paths/storage_files.yml"
+ "/api/v3/storages/{id}/files/prepare_upload":
+ "$ref": "./paths/storage_files_prepare_upload.yml"
"/api/v3/storages/{id}/oauth_client_credentials":
"$ref": "./paths/storage_oauth_client_credentials.yml"
"/api/v3/time_entries":
@@ -752,6 +754,10 @@ components:
"$ref": "./components/schemas/storage_file_model.yml"
StorageFileLocationModel:
"$ref": "./components/schemas/storage_file_location_model.yml"
+ StorageFileUploadPreparationModel:
+ "$ref": "./components/schemas/storage_file_upload_preparation_model.yml"
+ StorageFileUploadLinkModel:
+ "$ref": "./components/schemas/storage_file_upload_link_model.yml"
StorageReadModel:
"$ref": "./components/schemas/storage_read_model.yml"
StorageWriteModel:
@@ -760,24 +766,14 @@ components:
"$ref": "./components/schemas/time_entry_model.yml"
Time_Entry_ActivityModel:
"$ref": "./components/schemas/time_entry_activity_model.yml"
- Time_entry_create_form:
- "$ref": "./components/schemas/time_entry_create_form.yml"
- Time_entry_update_form:
- "$ref": "./components/schemas/time_entry_update_form.yml"
TypeModel:
"$ref": "./components/schemas/type_model.yml"
TypesModel:
"$ref": "./components/schemas/types_model.yml"
Types_by_ProjectModel:
"$ref": "./components/schemas/types_by_project_model.yml"
- Unlock_user:
- "$ref": "./components/schemas/unlock_user.yml"
Unstar_QueryModel:
"$ref": "./components/schemas/unstar_query_model.yml"
- Update_User:
- "$ref": "./components/schemas/update_user.yml"
- Update_group:
- "$ref": "./components/schemas/update_group.yml"
UserCollectionModel:
"$ref": "./components/schemas/user_collection_model.yml"
UserCreateModel:
diff --git a/docs/api/apiv3/paths/storage.yml b/docs/api/apiv3/paths/storage.yml
index 752fc552640..03dda22c95a 100644
--- a/docs/api/apiv3/paths/storage.yml
+++ b/docs/api/apiv3/paths/storage.yml
@@ -116,12 +116,10 @@ delete:
application/hal+json:
schema:
$ref: '../components/schemas/error_response.yml'
- examples:
- response:
- value:
- _type: Error
- errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission
- message: You are not authorized to access this resource.
+ example:
+ _type: Error
+ errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission
+ message: You are not authorized to access this resource.
description: |-
Returned if the client does not have sufficient permissions.
diff --git a/docs/api/apiv3/paths/storage_files.yml b/docs/api/apiv3/paths/storage_files.yml
index 61f4a3e25b3..676118fc766 100644
--- a/docs/api/apiv3/paths/storage_files.yml
+++ b/docs/api/apiv3/paths/storage_files.yml
@@ -44,6 +44,19 @@ get:
_type: Error
errorIdentifier: urn:openproject-org:api:v3:errors:InvalidQuery
message: The given parent is not a directory.
+ '403':
+ content:
+ application/hal+json:
+ schema:
+ $ref: '../components/schemas/error_response.yml'
+ example:
+ _type: Error
+ errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission
+ message: You are not authorized to access this resource.
+ description: |-
+ Returned if the client does not have sufficient permissions.
+
+ **Required permission:** manage file links
'404':
content:
application/hal+json:
diff --git a/docs/api/apiv3/paths/storage_files_prepare_upload.yml b/docs/api/apiv3/paths/storage_files_prepare_upload.yml
new file mode 100644
index 00000000000..a78d0892994
--- /dev/null
+++ b/docs/api/apiv3/paths/storage_files_prepare_upload.yml
@@ -0,0 +1,58 @@
+# /api/v3/storages/{id}/files/prepare_upload
+---
+post:
+ summary: Preparation of a direct upload of a file to the given storage.
+ operationId: prepare_storage_file_upload
+ tags:
+ - File links
+ description: |-
+ Executes a request that prepares a link for a direct upload to the storage.
+
+ The background here is, that the client needs to make a direct request to the storage instance for file uploading,
+ but should not get access to the credentials, which are stored in the backend. The response contains a link object,
+ that enables the client to execute a file upload without the real credentials.
+ parameters:
+ - name: id
+ description: Storage id
+ in: path
+ required: true
+ schema:
+ type: integer
+ example: 1337
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: '../components/schemas/storage_file_upload_preparation_model.yml'
+ responses:
+ '201':
+ description: OK
+ content:
+ application/hal+json:
+ schema:
+ $ref: '../components/schemas/storage_file_upload_link_model.yml'
+ '400':
+ description: Returned if the given parent parameter value does not refer to a directory.
+ content:
+ application/hal+json:
+ schema:
+ $ref: '../components/schemas/error_response.yml'
+ example:
+ _type: Error
+ errorIdentifier: urn:openproject-org:api:v3:errors:InvalidQuery
+ message: The given parent is not a directory.
+ '404':
+ content:
+ application/hal+json:
+ schema:
+ $ref: '../components/schemas/error_response.yml'
+ example:
+ _type: Error
+ errorIdentifier: urn:openproject-org:api:v3:errors:NotFound
+ message: The requested resource could not be found.
+ description: |-
+ Returned in either of those cases:
+ - if the storage does not exist or the client does not have sufficient permissions to see it
+
+ **Required permission:** view file links
+ - if the document root file identification does not exist on the storage
diff --git a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
index 72c91b3d648..29595f1a0c4 100644
--- a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
+++ b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
@@ -48,12 +48,6 @@ module API::V3::StorageFiles
)
end
- # RequestBody:
- # {
- # "projectId": 42
- # "fileName": "ape.png",
- # "parent": "/Pictures"
- # }
post :prepare_upload do
raise ::API::Errors::NotFound unless OpenProject::FeatureDecisions.storage_file_upload_active?