fix(project): recursively get all users from all parent projects
This commit is contained in:
parent
19f69419f7
commit
0cd633981a
@ -171,6 +171,7 @@
|
|||||||
identifier: test19
|
identifier: test19
|
||||||
owner_id: 7
|
owner_id: 7
|
||||||
position: 19
|
position: 19
|
||||||
|
parent_project_id: 29
|
||||||
updated: 2018-12-02 15:13:12
|
updated: 2018-12-02 15:13:12
|
||||||
created: 2018-12-01 15:13:12
|
created: 2018-12-01 15:13:12
|
||||||
# User 1 does not have access to this project
|
# User 1 does not have access to this project
|
||||||
@ -260,11 +261,19 @@
|
|||||||
id: 27
|
id: 27
|
||||||
title: Test27
|
title: Test27
|
||||||
owner_id: 6
|
owner_id: 6
|
||||||
|
position: 2700
|
||||||
updated: 2018-12-02 15:13:12
|
updated: 2018-12-02 15:13:12
|
||||||
created: 2018-12-01 15:13:12
|
created: 2018-12-01 15:13:12
|
||||||
-
|
-
|
||||||
id: 28
|
id: 28
|
||||||
title: Test28
|
title: Test28
|
||||||
owner_id: 6
|
owner_id: 6
|
||||||
|
position: 2800
|
||||||
|
updated: 2018-12-02 15:13:12
|
||||||
|
created: 2018-12-01 15:13:12
|
||||||
|
-
|
||||||
|
id: 29
|
||||||
|
title: Test29
|
||||||
|
owner_id: 6
|
||||||
updated: 2018-12-02 15:13:12
|
updated: 2018-12-02 15:13:12
|
||||||
created: 2018-12-01 15:13:12
|
created: 2018-12-01 15:13:12
|
||||||
|
@ -58,3 +58,21 @@
|
|||||||
right: 0
|
right: 0
|
||||||
updated: 2018-12-02 15:13:12
|
updated: 2018-12-02 15:13:12
|
||||||
created: 2018-12-01 15:13:12
|
created: 2018-12-01 15:13:12
|
||||||
|
- id: 10
|
||||||
|
team_id: 11
|
||||||
|
project_id: 29
|
||||||
|
right: 0
|
||||||
|
updated: 2018-12-02 15:13:12
|
||||||
|
created: 2018-12-01 15:13:12
|
||||||
|
- id: 11
|
||||||
|
team_id: 12
|
||||||
|
project_id: 29
|
||||||
|
right: 1
|
||||||
|
updated: 2018-12-02 15:13:12
|
||||||
|
created: 2018-12-01 15:13:12
|
||||||
|
- id: 12
|
||||||
|
team_id: 13
|
||||||
|
project_id: 29
|
||||||
|
right: 2
|
||||||
|
updated: 2018-12-02 15:13:12
|
||||||
|
created: 2018-12-01 15:13:12
|
||||||
|
@ -58,3 +58,21 @@
|
|||||||
right: 0
|
right: 0
|
||||||
updated: 2018-12-02 15:13:12
|
updated: 2018-12-02 15:13:12
|
||||||
created: 2018-12-01 15:13:12
|
created: 2018-12-01 15:13:12
|
||||||
|
- id: 10
|
||||||
|
user_id: 11
|
||||||
|
project_id: 29
|
||||||
|
right: 0
|
||||||
|
updated: 2018-12-02 15:13:12
|
||||||
|
created: 2018-12-01 15:13:12
|
||||||
|
- id: 11
|
||||||
|
user_id: 12
|
||||||
|
project_id: 29
|
||||||
|
right: 1
|
||||||
|
updated: 2018-12-02 15:13:12
|
||||||
|
created: 2018-12-01 15:13:12
|
||||||
|
- id: 12
|
||||||
|
user_id: 13
|
||||||
|
project_id: 29
|
||||||
|
right: 2
|
||||||
|
updated: 2018-12-02 15:13:12
|
||||||
|
created: 2018-12-01 15:13:12
|
||||||
|
@ -303,7 +303,7 @@ func TestProject_ReadAll(t *testing.T) {
|
|||||||
projects := []*Project{}
|
projects := []*Project{}
|
||||||
_, _, err := getAllProjectsForUser(s, 1, nil, &projectOptions{}, &projects, 0)
|
_, _, err := getAllProjectsForUser(s, 1, nil, &projectOptions{}, &projects, 0)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 10, len(projects))
|
assert.Equal(t, 12, len(projects))
|
||||||
_ = s.Close()
|
_ = s.Close()
|
||||||
})
|
})
|
||||||
t.Run("only child projects for one project", func(t *testing.T) {
|
t.Run("only child projects for one project", func(t *testing.T) {
|
||||||
@ -319,7 +319,7 @@ func TestProject_ReadAll(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, reflect.TypeOf(projects3).Kind(), reflect.Slice)
|
assert.Equal(t, reflect.TypeOf(projects3).Kind(), reflect.Slice)
|
||||||
ls := projects3.([]*Project)
|
ls := projects3.([]*Project)
|
||||||
assert.Equal(t, 10, len(ls))
|
assert.Equal(t, 12, len(ls))
|
||||||
assert.Equal(t, int64(3), ls[0].ID) // Project 3 has a position of 1 and should be sorted first
|
assert.Equal(t, int64(3), ls[0].ID) // Project 3 has a position of 1 and should be sorted first
|
||||||
assert.Equal(t, int64(1), ls[1].ID)
|
assert.Equal(t, int64(1), ls[1].ID)
|
||||||
assert.Equal(t, int64(6), ls[2].ID)
|
assert.Equal(t, int64(6), ls[2].ID)
|
||||||
|
@ -34,6 +34,14 @@ func ListUsersFromProject(s *xorm.Session, l *Project, search string) (users []*
|
|||||||
|
|
||||||
userids := []*ProjectUIDs{}
|
userids := []*ProjectUIDs{}
|
||||||
|
|
||||||
|
var currentProject *Project
|
||||||
|
currentProject, err = GetProjectSimpleByID(s, l.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
currentUserIDs := []*ProjectUIDs{}
|
||||||
err = s.
|
err = s.
|
||||||
Select(`l.owner_id as projectOwner,
|
Select(`l.owner_id as projectOwner,
|
||||||
ul.user_id as ulID,
|
ul.user_id as ulID,
|
||||||
@ -57,12 +65,28 @@ func ListUsersFromProject(s *xorm.Session, l *Project, search string) (users []*
|
|||||||
builder.Or(builder.Eq{"ul.right": RightAdmin}),
|
builder.Or(builder.Eq{"ul.right": RightAdmin}),
|
||||||
builder.Or(builder.Eq{"tl.right": RightAdmin}),
|
builder.Or(builder.Eq{"tl.right": RightAdmin}),
|
||||||
),
|
),
|
||||||
builder.Eq{"l.id": l.ID},
|
builder.Eq{"l.id": currentProject.ID},
|
||||||
).
|
).
|
||||||
Find(&userids)
|
Find(¤tUserIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
userids = append(userids, currentUserIDs...)
|
||||||
|
|
||||||
|
if currentProject.ParentProjectID == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
parent, err := GetProjectSimpleByID(s, currentProject.ParentProjectID)
|
||||||
|
if err != nil && !IsErrProjectDoesNotExist(err) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err != nil && IsErrProjectDoesNotExist(err) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
currentProject = parent
|
||||||
|
}
|
||||||
|
|
||||||
// Remove duplicates from the project of ids and make it a slice
|
// Remove duplicates from the project of ids and make it a slice
|
||||||
uidmap := make(map[int64]bool)
|
uidmap := make(map[int64]bool)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user