From 60fa21133454f100948aba74f012b4cbab4449ff Mon Sep 17 00:00:00 2001 From: jd Date: Sat, 28 Sep 2024 09:06:32 +0000 Subject: [PATCH] fix: partial fix to allow list tasks in ios reminders app (#2717) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR introduces a partial fix for the CalDAV task listing bug (#753) when handling PROPFIND requests with `Depth: 1`, improving task visibility in the iOS Reminders app. Notes: * This might make Thunderbird somewhat usable when interacting with tasks using the `/dav/projects/{id} url`. * This does not fully resolve the issue where the Reminders app will only display the last project after some time when adding the URL. This is my first time working with Golang and CalDAV, so I’d really appreciate any feedback or suggestions on the code structure, style, or any improvements I could make. Co-authored-by: JD <43763092+jdw1023@users.noreply.github.com> Reviewed-on: https://kolaente.dev/vikunja/vikunja/pulls/2717 Reviewed-by: konrad Co-authored-by: jd Co-committed-by: jd (cherry picked from commit 84dbc5fd8467418be6390f4fe9eee9abdc50bf45) --- pkg/routes/caldav/listStorageProvider.go | 30 ++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/pkg/routes/caldav/listStorageProvider.go b/pkg/routes/caldav/listStorageProvider.go index aa8113cb5..2fb6cec67 100644 --- a/pkg/routes/caldav/listStorageProvider.go +++ b/pkg/routes/caldav/listStorageProvider.go @@ -52,7 +52,7 @@ type VikunjaCaldavProjectStorage struct { } // GetResources returns either all projects, links to the principal, or only one project, depending on the request -func (vcls *VikunjaCaldavProjectStorage) GetResources(rpath string, _ bool) ([]data.Resource, error) { +func (vcls *VikunjaCaldavProjectStorage) GetResources(rpath string, withChildren bool) ([]data.Resource, error) { // It looks like we need to have the same handler for returning both the calendar home set and the user principal // Since the client seems to ignore the whatever is being returned in the first request and just makes a second one @@ -92,6 +92,24 @@ func (vcls *VikunjaCaldavProjectStorage) GetResources(rpath string, _ bool) ([]d } r := data.NewResource(rpath, &rr) r.Name = vcls.project.Title + + // If the request is withChildren (Depth: 1), we need to return all tasks of the project + if withChildren { + resources := []data.Resource{r} + + // Check if there are tasks to iterate over + if vcls.project.Tasks != nil { + for i := range vcls.project.Tasks { + taskResource := VikunjaProjectResourceAdapter{ + project: vcls.project, + task: &vcls.project.Tasks[i].Task, + isCollection: false, + } + addTaskResource(&vcls.project.Tasks[i].Task, &taskResource, &resources) + } + } + return resources, nil + } return []data.Resource{r}, nil } @@ -163,9 +181,7 @@ func (vcls *VikunjaCaldavProjectStorage) GetResourcesByList(rpaths []string) (re rr := VikunjaProjectResourceAdapter{ task: t, } - r := data.NewResource(getTaskURL(t), &rr) - r.Name = t.Title - resources = append(resources, r) + addTaskResource(t, &rr, &resources) } return @@ -671,3 +687,9 @@ func (vcls *VikunjaCaldavProjectStorage) getProjectRessource(isCollection bool) return } + +func addTaskResource(task *models.Task, rr *VikunjaProjectResourceAdapter, resources *[]data.Resource) { + taskResourceInstance := data.NewResource(getTaskURL(task), rr) + taskResourceInstance.Name = task.Title + *resources = append(*resources, taskResourceInstance) +}