fix(tasks): get all tasks from parent projects
This commit is contained in:
parent
ceaa9c0e03
commit
537ba60f2d
@ -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
|
||||
-
|
||||
@ -253,3 +256,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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -52,3 +52,9 @@
|
||||
right: 0
|
||||
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
|
||||
|
@ -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},
|
||||
|
@ -182,7 +182,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()},
|
||||
@ -192,9 +192,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}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -407,7 +408,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),
|
||||
@ -416,26 +417,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),
|
||||
}
|
||||
@ -446,7 +447,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),
|
||||
@ -459,7 +460,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),
|
||||
@ -472,7 +473,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),
|
||||
@ -637,7 +638,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want interface{}
|
||||
want []*Task
|
||||
wantErr bool
|
||||
}
|
||||
|
||||
@ -675,8 +676,8 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||
task22,
|
||||
task23,
|
||||
task24,
|
||||
task25,
|
||||
task26,
|
||||
//task25,
|
||||
//task26,
|
||||
task27,
|
||||
task28,
|
||||
task29,
|
||||
@ -812,11 +813,13 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||
task19,
|
||||
task20,
|
||||
task21,
|
||||
|
||||
task22,
|
||||
task23,
|
||||
task24,
|
||||
task25,
|
||||
task26,
|
||||
|
||||
task27,
|
||||
task28,
|
||||
task29,
|
||||
@ -1241,11 +1244,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, \nwant %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, \nwant %v, \ndiff: %v \n\n diffIDs: %v", tt.name, got, tt.want, diff, diffIDs)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user