From 415c6380a52fa15d1765cd3d4915bc0e76b1349a Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 14 Feb 2024 14:59:58 +0100 Subject: [PATCH] feat(api tokens): add task attachment to api scopes This explicitly adds download and upload of task attachments. Because these are not handled with the usual CRUDables, they were not picked up automatically. Resolves https://github.com/go-vikunja/vikunja/issues/112 --- pkg/models/api_routes.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/models/api_routes.go b/pkg/models/api_routes.go index 7afe2f969..211c81251 100644 --- a/pkg/models/api_routes.go +++ b/pkg/models/api_routes.go @@ -69,7 +69,7 @@ func getRouteGroupName(path string) string { // CollectRoutesForAPITokenUsage gets called for every added APITokenRoute and builds a list of all routes we can use for the api tokens. func CollectRoutesForAPITokenUsage(route echo.Route) { - if !strings.Contains(route.Name, "(*WebHandler)") { + if !strings.Contains(route.Name, "(*WebHandler)") && !strings.Contains(route.Name, "Attachment") { return } @@ -116,6 +116,21 @@ func CollectRoutesForAPITokenUsage(route echo.Route) { Method: route.Method, } } + + if routeGroupName == "tasks_attachments" { + if strings.Contains(route.Name, "UploadTaskAttachment") { + apiTokenRoutes[routeGroupName].Create = &RouteDetail{ + Path: route.Path, + Method: route.Method, + } + } + if strings.Contains(route.Name, "GetTaskAttachment") { + apiTokenRoutes[routeGroupName].ReadOne = &RouteDetail{ + Path: route.Path, + Method: route.Method, + } + } + } } // GetAvailableAPIRoutesForToken returns a list of all API routes which are available for token usage.