Content
View differences
Updated by Wieland Lindenthal over 4 years ago
# This specification is "Work in progress" and is not yet finished.
## Nextcloud file identifiers in OpenProject
In Nextcloud every file has an `id` and a `fileid`. The `id` differentiates a file from another within the same Nextcloud instance. The `fileid` in contrast is globally unique as it is a composition of the unique Nextcloud instance ID and the file's `id`. More information on this [here.](https://help.nextcloud.com/t/difference-between-id-and-fileid-in-webdav/91414) In OpenProject we use the `fileid` as we might want to support multiple Nextcloud instances in the future and still want to have a simple way to query on them. By using the `fileid` we only need one value to identify a file and not two (file id and instance id).
## File link (link) resources
`FileLink` `File` resources in OpenProject describe links between resources in OpenProject (first work (work packages, maybe in the future wiki pages, etc.) and their representation in a file store, i.e. a file in Nextcloud or in a Google Drive.
## GET all file links to work packages of project a project from a certain file store ### Example:
Example: _"Get all file links linking files linked to work packages in project 5 that are stored in file store 1"_
For readability reasons we chose to show the URL params not URL encoded in this example. The params must be URL encoded first if you want to use them in a real example.
`GET /api/v3/file_links?filters=[{"resource_type":{"operator":"=","values":["WorkPackage"]}},{"project_id":{"operator":"=","values":["5"]}},{"file_store":{"operator":"=","values":["1"]}}]` `/api/v3/files?filters=[{"resource_type":{"operator":"=","values":["WorkPackage"]}},{"project_id":{"operator":"=","values":["5"]}},{"file_store":{"operator":"=","values":[""]}}]`
This will return a collection of file reference resources.
```json
{
"_type" : "collection",
"count" : 2,
"total" : 2,
"_embedded" : {
"elements" : [
{
"id" : 1,
"storageType" : "nextcloud",
"storageId" : 1, "5502",
"originData" : {
"id" : 5502
"createdAt" : "2021-12-20T13:37:45Z",
"lastModifiedAt" : "2021-12-20T14:27:01Z",
"authorName" : "Manuel Müller",
"lastModifiedByName" : "Christina Bolz",
"path" : "/documents/images",
"fileName" : "picture_1.png",
"mimeType" : "image/png",
},
"_links" : {
"self" : {
"href" : "/api/v3/file_links/1", "/api/v3/files/1",
"title" : "picture_1.png"
},
"downloadLocation" : "https://mynextcloud.com/..."
"staticDownloadLocation" : "/api/v3/file_links/1/download", "/api/v3/files/1/download",
"preview/thumbnail/..." : "/api/v3/files/1/preview",
"origin" : "https://mynextcloud.com/index.php/apps/files/?fileid=5502",
"author" : {
"href" : "/api/v3/users/3145",
"title" : "Richard Wolf",
},
"delete" : {
"href" : "/api/v3/file_links/1", "/api/v3/files/1",
"method" : "delete"
},
"container" : {
"href" : "/api/v3/work_packages/22",
"title" : "Awesome work package with file references"
}
},
"_type" : "FileLink" "File"
},
{
...another file link
}
]
}
},
```
## GET work Work packages that are related to file link a Nextcloud "fileid"
To query all work packages that are linked to a Nextcloud file you need to apply the filter `originId` `nextcloudFileid` to the `work_packages` API endpoint. This The filter allows only one operator `=` and multiple IDs `fileid`s as values, for example in case of a Nextcloud storage the IDs are Nextclouds `fileid`s. values.
### Example:
_"Get all work packages that are linked related to two certain files with their original IDs being 1234 and 1235."_ a Nextcoud_ `_fileid_`_"_
Attention: For readability reasons we chose to show the URL params not URL encoded in this example. The params must be URL encoded first if you want to use them in a real example.
`GET /api/v3/work_packages?filters=[{"originId":{"operator":"=","values":["1234","1235"]}}]` `/api/v3/work_packages?filters=[{"nextcloudFileid":{"operator":"=","values":["00001234","00001235"]}}]`
This will return a collection of work package resources.
## **GET file links **Files that are related to a work package**
For displaying To query all links to all linked files next to a work package, for example in a "Nextcloud" tab of a work package, we need to be able to query all file links linking to a work package.
Example: _"Get me all files that are linked to work package 1."_
For readability reasons we chose to show the URL params not URL encoded in this example. The params must be URL encoded first if you want to use them in a real example.
`GET /api/v3/file_links?filters=[{"container_type":{"operator":"=","values":["WorkPackage"]}},{"container_id":{"operator":"=","values":["1"]}}]`
## CREATE a file link
To create a link between a file and a work package we need make a POST request, containing the storage ID, the original file ID (i.e. Nextcloud's `fileid`) and the work package ID.
Example: "Create a link between work package 2 and file 1234 in storage 1."
`POST /api/v3/file_links`
with payload
```json
{
"storageId" : 1,
"originId" : 1234,
"workPackageId" : 2
}
```
The return value will be the created `FileLink` resource as described above.
## DELETE a file link
Example: _"Delete file link with ID 1."_
`DELETE /api/v3/file_links/1`
## Nice to have: UPDATE origin data of a file link
It might be necessary to offer a way to update the origin data of a file link as files attributes could change at its origin, such as its file name, mime type, last modified timestamp and the name of the person that last modified the file. However, I am not sure if we will really need it in the first version.
##
In Nextcloud every file has an `id` and a `fileid`. The `id` differentiates a file from another within the same Nextcloud instance. The `fileid` in contrast is globally unique as it is a composition of the unique Nextcloud instance ID and the file's `id`. More information on this [here.](https://help.nextcloud.com/t/difference-between-id-and-fileid-in-webdav/91414) In OpenProject we use the `fileid` as we might want to support multiple Nextcloud instances in the future and still want to have a simple way to query on them. By using the `fileid` we only need one value to identify a file and not two (file id and instance id).
##
`FileLink`
## GET all file links to work packages of project a project from a certain file store
Example: _"Get all file links linking
For readability reasons we chose to show the URL params not URL encoded in this example. The params must be URL encoded first if you want to use them in a real example.
`GET /api/v3/file_links?filters=[{"resource_type":{"operator":"=","values":["WorkPackage"]}},{"project_id":{"operator":"=","values":["5"]}},{"file_store":{"operator":"=","values":["1"]}}]`
This will return a collection of file reference resources.
```json
{
"count" : 2,
"total" : 2,
"_embedded" : {
"elements" : [
{
"id" : 1,
"storageType" : "nextcloud",
"storageId" : 1,
"originData" : {
"id" : 5502
"createdAt" : "2021-12-20T13:37:45Z",
"lastModifiedAt" : "2021-12-20T14:27:01Z",
"authorName" : "Manuel Müller",
"lastModifiedByName" : "Christina Bolz",
"mimeType" : "image/png",
},
"_links" : {
"self" : {
"href" : "/api/v3/file_links/1",
"title" : "picture_1.png"
},
"downloadLocation" : "https://mynextcloud.com/..."
"staticDownloadLocation" : "/api/v3/file_links/1/download",
"author" : {
"href" : "/api/v3/users/3145",
"title" : "Richard Wolf",
},
"delete" : {
"href" : "/api/v3/file_links/1",
"method" : "delete"
},
"container" : {
"title" : "Awesome work package with file references"
}
},
"_type" : "FileLink"
},
{
...another file link
}
]
}
},
```
## GET work
To query all work packages that are linked to a
Attention: For readability reasons we chose to show the URL params not URL encoded in this example. The params must be URL encoded first if you want to use them in a real example.
`GET /api/v3/work_packages?filters=[{"originId":{"operator":"=","values":["1234","1235"]}}]`
This will return a collection of work package resources.
## **GET file links
For displaying
Example: _"Get me all files that are linked to work package 1."_
For readability reasons we chose to show the URL params not URL encoded in this example. The params must be URL encoded first if you want to use them in a real example.
`GET /api/v3/file_links?filters=[{"container_type":{"operator":"=","values":["WorkPackage"]}},{"container_id":{"operator":"=","values":["1"]}}]`
## CREATE a file link
To create a link between a file and a work package we need make a POST request, containing the storage ID, the original file ID (i.e. Nextcloud's `fileid`) and the work package ID.
Example: "Create a link between work package 2 and file 1234 in storage 1."
`POST /api/v3/file_links`
with payload
```json
{
"storageId" : 1,
"originId" : 1234,
"workPackageId" : 2
}
```
The return value will be the created `FileLink` resource as described above.
## DELETE a file link
Example: _"Delete file link with ID 1."_
`DELETE /api/v3/file_links/1`
## Nice to have: UPDATE origin data of a file link
It might be necessary to offer a way to update the origin data of a file link as files attributes could change at its origin, such as its file name, mime type, last modified timestamp and the name of the person that last modified the file. However, I am not sure if we will really need it in the first version.