fix: resolve sql request and logic

This commit is contained in:
Malcolm Smith 2026-06-27 11:18:56 -07:00
parent c11284a9ea
commit 9aa4ea640b
2 changed files with 20 additions and 50 deletions

View File

@ -211,50 +211,40 @@ func getRelevantProjectsFromCollection(s *xorm.Session, a web.Auth, tf *TaskColl
return []*Project{{ID: tf.ProjectID}}, nil
}
projectIDs, err := getProjectAndDescendantIDs(s, tf.ProjectID)
allProjects, _, _, err := getRawProjectsForUser(s, &projectOptions{
user: &user.User{ID: a.GetID()},
page: -1,
})
if err != nil {
return nil, err
}
u, err := user.GetUserByID(s, a.GetID())
if err != nil {
return nil, err
relevantProjects := make([]*Project, 0)
childrenMap := make(map[int64][]int64)
projectMap := make(map[int64]*Project)
for _, p := range allProjects {
projectMap[p.ID] = p
childrenMap[p.ParentProjectID] = append(childrenMap[p.ParentProjectID], p.ID)
}
projectPermissions, err := checkPermissionsForProjects(s, u, projectIDs)
if err != nil {
return nil, err
}
queue := []int64{tf.ProjectID}
for len(queue) > 0 {
currentID := queue[0]
queue = queue[1:]
relevantProjects := make([]*Project, 0, len(projectIDs))
for _, projectID := range projectIDs {
permission, has := projectPermissions[projectID]
if !has || permission.MaxPermission < PermissionRead {
continue
if p, exists := projectMap[currentID]; exists {
relevantProjects = append(relevantProjects, p)
}
relevantProjects = append(relevantProjects, &Project{ID: projectID})
if children, exists := childrenMap[currentID]; exists {
queue = append(queue, children...)
}
}
return relevantProjects, nil
}
func getProjectAndDescendantIDs(s *xorm.Session, rootProjectID int64) (projectIDs []int64, err error) {
err = s.SQL(`
WITH RECURSIVE descendant_projects (id) AS (
SELECT id
FROM projects
WHERE id = ?
UNION ALL
SELECT p.id
FROM projects p
INNER JOIN descendant_projects dp ON p.parent_project_id = dp.id
)
SELECT DISTINCT id
FROM descendant_projects`, rootProjectID).
Find(&projectIDs)
return
}
func getFilterValueForBucketFilter(filter string, view *ProjectView) (newFilter string, err error) {
if view.BucketConfigurationMode != BucketConfigurationModeFilter {
@ -405,10 +395,6 @@ func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, pa
tf.ProjectID > 0 &&
!tf.isSavedFilter
if view != nil && view.ViewKind == ProjectViewKindKanban {
effectiveIncludeSubprojects = false
}
if _, is := a.(*LinkSharing); is {
effectiveIncludeSubprojects = false
}

View File

@ -1911,23 +1911,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
}
}
func TestGetProjectAndDescendantIDs(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
t.Run("single project", func(t *testing.T) {
projectIDs, err := getProjectAndDescendantIDs(s, 1)
require.NoError(t, err)
assert.ElementsMatch(t, []int64{1}, projectIDs)
})
t.Run("recursive descendants", func(t *testing.T) {
projectIDs, err := getProjectAndDescendantIDs(s, 12)
require.NoError(t, err)
assert.ElementsMatch(t, []int64{12, 25, 26}, projectIDs)
})
}
func TestTaskCollection_SubtaskRemainsAfterMove(t *testing.T) {
db.LoadAndAssertFixtures(t)