From 68d4dcd7e67583f4ec3f5b1dfadb2e9be3f09392 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 7 Sep 2023 10:56:59 +0200 Subject: [PATCH] fix(projects): don't limit results to top-level projects when searching Resolves https://github.com/go-vikunja/api/issues/82 --- pkg/models/project.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pkg/models/project.go b/pkg/models/project.go index b13f7f72d73..9c3d398f00d 100644 --- a/pkg/models/project.go +++ b/pkg/models/project.go @@ -368,18 +368,20 @@ func getUserProjectsStatement(parentProjectIDs []int64, userID int64, search str } var parentCondition builder.Cond - parentCondition = builder.Or( - builder.IsNull{"l.parent_project_id"}, - builder.Eq{"l.parent_project_id": 0}, - // else check for shared sub projects with a parent - builder.And( - builder.Or( - builder.NotNull{"tm2.user_id"}, - builder.NotNull{"ul.user_id"}, + if search == "" { + parentCondition = builder.Or( + builder.IsNull{"l.parent_project_id"}, + builder.Eq{"l.parent_project_id": 0}, + // else check for shared sub projects with a parent + builder.And( + builder.Or( + builder.NotNull{"tm2.user_id"}, + builder.NotNull{"ul.user_id"}, + ), + builder.NotNull{"l.parent_project_id"}, ), - builder.NotNull{"l.parent_project_id"}, - ), - ) + ) + } projectCol := "id" if len(parentProjectIDs) > 0 { parentCondition = builder.In("l.parent_project_id", parentProjectIDs)