fix(tasks): get all tasks from parent projects

This commit is contained in:
kolaente 2023-01-07 12:41:11 +01:00
parent 36819a8cca
commit 6008046505
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
7 changed files with 75 additions and 28 deletions

View File

@ -104,6 +104,7 @@
identifier: test12
owner_id: 6
position: 12
parent_project_id: 27
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
-
@ -131,6 +132,7 @@
identifier: test15
owner_id: 6
position: 15
parent_project_id: 28
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
-
@ -188,6 +190,7 @@
identifier: test21
owner_id: 1
position: 21
parent_project_id: 22
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
-
@ -232,3 +235,15 @@
parent_project_id: 25
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
-
id: 27
title: Test27
owner_id: 6
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
-
id: 28
title: Test28
owner_id: 6
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12

View File

@ -202,18 +202,18 @@
title: 'task #22'
done: false
created_by_id: 6
project_id: 13
project_id: 12
index: 1
bucket_id: 13
bucket_id: 12
created: 2018-12-01 01:12:04
updated: 2018-12-01 01:12:04
- id: 23
title: 'task #23'
done: false
created_by_id: 6
project_id: 14
project_id: 12
index: 1
bucket_id: 14
bucket_id: 12
created: 2018-12-01 01:12:04
updated: 2018-12-01 01:12:04
- id: 24

View File

@ -52,3 +52,9 @@
right: 0
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 9
team_id: 1
project_id: 28
right: 0
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12

View File

@ -46,3 +46,9 @@
right: 2
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12
- id: 9
user_id: 1
project_id: 27
right: 0
updated: 2018-12-02 15:13:12
created: 2018-12-01 15:13:12

View File

@ -405,19 +405,21 @@ func getUserProjectsStatement(parentProjectIDs []int64, userID int64, search str
var parentCondition builder.Cond
parentCondition = builder.Or(
builder.IsNull{"parent_project_id"},
builder.Eq{"parent_project_id": 0},
builder.IsNull{"l.parent_project_id"},
builder.Eq{"l.parent_project_id": 0},
)
projectCol := "id"
if len(parentProjectIDs) > 0 {
parentCondition = builder.In("parent_project_id", parentProjectIDs)
parentCondition = builder.In("l.parent_project_id", parentProjectIDs)
projectCol = "parent_project_id"
}
return builder.Dialect(dialect).
Select("l.*").
From("projects", "l").
Join("LEFT", "team_projects tl", "l.id = tl.project_id").
Join("LEFT", "team_projects tl", "tl.project_id = l."+projectCol).
Join("LEFT", "team_members tm2", "tm2.team_id = tl.team_id").
Join("LEFT", "users_projects ul", "ul.project_id = l.id").
Join("LEFT", "users_projects ul", "ul.project_id = l."+projectCol).
Where(builder.And(
builder.Or(
builder.Eq{"tm2.user_id": userID},

View File

@ -179,7 +179,7 @@ func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, pa
// This allows to use this function in Task.ReadAll with a possibility to deprecate the latter at some point.
var projects []*Project
if tf.ProjectID == 0 {
projectMap, _, _, err := getRawProjectsForUser(
projects, _, _, err = getRawProjectsForUser(
s,
&projectOptions{
user: &user.User{ID: a.GetID()},
@ -189,9 +189,6 @@ func (tf *TaskCollection) ReadAll(s *xorm.Session, a web.Auth, search string, pa
if err != nil {
return nil, 0, 0, err
}
for _, project := range projectMap {
projects = append(projects, project)
}
} else {
// Check the project exists and the user has access on it
project := &Project{ID: tf.ProjectID}

View File

@ -17,6 +17,7 @@
package models
import (
"sort"
"testing"
"time"
@ -399,7 +400,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Index: 1,
CreatedByID: 6,
CreatedBy: user6,
ProjectID: 12,
ProjectID: 12, // parent project is shared to user 1 via direct share
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 12,
Created: time.Unix(1543626724, 0).In(loc),
@ -408,26 +409,26 @@ func TestTaskCollection_ReadAll(t *testing.T) {
task22 := &Task{
ID: 22,
Title: "task #22",
Identifier: "test13-1",
Identifier: "test12-1",
Index: 1,
CreatedByID: 6,
CreatedBy: user6,
ProjectID: 13,
ProjectID: 12,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 13,
BucketID: 12,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
task23 := &Task{
ID: 23,
Title: "task #23",
Identifier: "test14-1",
Identifier: "test12-1",
Index: 1,
CreatedByID: 6,
CreatedBy: user6,
ProjectID: 14,
ProjectID: 12,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 14,
BucketID: 12,
Created: time.Unix(1543626724, 0).In(loc),
Updated: time.Unix(1543626724, 0).In(loc),
}
@ -438,7 +439,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Index: 1,
CreatedByID: 6,
CreatedBy: user6,
ProjectID: 15,
ProjectID: 15, // parent project is shared to user 1 via team
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 15,
Created: time.Unix(1543626724, 0).In(loc),
@ -451,7 +452,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Index: 1,
CreatedByID: 6,
CreatedBy: user6,
ProjectID: 16,
ProjectID: 15,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 16,
Created: time.Unix(1543626724, 0).In(loc),
@ -464,7 +465,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Index: 1,
CreatedByID: 6,
CreatedBy: user6,
ProjectID: 17,
ProjectID: 15,
RelatedTasks: map[RelationKind][]*Task{},
BucketID: 17,
Created: time.Unix(1543626724, 0).In(loc),
@ -612,7 +613,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
name string
fields fields
args args
want interface{}
want []*Task
wantErr bool
}
@ -650,8 +651,8 @@ func TestTaskCollection_ReadAll(t *testing.T) {
task22,
task23,
task24,
task25,
task26,
//task25,
//task26,
task27,
task28,
task29,
@ -787,11 +788,13 @@ func TestTaskCollection_ReadAll(t *testing.T) {
task19,
task20,
task21,
task22,
task23,
task24,
task25,
task26,
task27,
task28,
task29,
@ -1216,11 +1219,29 @@ func TestTaskCollection_ReadAll(t *testing.T) {
return
}
if diff, equal := messagediff.PrettyDiff(got, tt.want); !equal {
if len(got.([]*Task)) == 0 && len(tt.want.([]*Task)) == 0 {
if len(got.([]*Task)) == 0 && len(tt.want) == 0 {
return
}
t.Errorf("Test %s, Task.ReadAll() = %v, want %v, \ndiff: %v", tt.name, got, tt.want, diff)
gotIDs := []int64{}
for _, t := range got.([]*Task) {
gotIDs = append(gotIDs, t.ID)
}
wantIDs := []int64{}
for _, t := range tt.want {
wantIDs = append(wantIDs, t.ID)
}
sort.Slice(wantIDs, func(i, j int) bool {
return wantIDs[i] < wantIDs[j]
})
sort.Slice(gotIDs, func(i, j int) bool {
return gotIDs[i] < gotIDs[j]
})
diffIDs, _ := messagediff.PrettyDiff(gotIDs, wantIDs)
t.Errorf("Test %s, Task.ReadAll() = %v, want %v, \ndiff: %v \n\n diffIDs: %v", tt.name, got, tt.want, diff, diffIDs)
}
})
}