From d5070a022d571d7d1fd49f038176bdd8f420dd9e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 5 Aug 2019 17:57:37 +0800 Subject: [PATCH 1/3] fix approvals counting --- models/org_team.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/models/org_team.go b/models/org_team.go index 1786376d02c8..799716679c4a 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -760,11 +760,14 @@ func IsUserInTeams(userID int64, teamIDs []int64) (bool, error) { } // UsersInTeamsCount counts the number of users which are in userIDs and teamIDs -func UsersInTeamsCount(userIDs []int64, teamIDs []int64) (count int64, err error) { - if count, err = x.In("uid", userIDs).In("team_id", teamIDs).Count(new(TeamUser)); err != nil { +func UsersInTeamsCount(userIDs []int64, teamIDs []int64) (int64, error) { + var ids []int64 + if err := x.In("uid", userIDs).In("team_id", teamIDs). + Table("team_user"). + Cols("uid").GroupBy("uid").Find(&ids); err != nil { return 0, err } - return + return int64(len(ids)), nil } // ___________ __________ From 77a5c45b06ccc630c57581132fbdcce2c5398e5e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 5 Aug 2019 23:44:46 +0800 Subject: [PATCH 2/3] fix tests --- models/org_team_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/org_team_test.go b/models/org_team_test.go index a81f9c07497c..d77fea4c46be 100644 --- a/models/org_team_test.go +++ b/models/org_team_test.go @@ -370,7 +370,7 @@ func TestUsersInTeamsCount(t *testing.T) { assert.Equal(t, expected, count) } - test([]int64{2}, []int64{1, 2, 3, 4}, 2) - test([]int64{1, 2, 3, 4, 5}, []int64{2, 5}, 2) - test([]int64{1, 2, 3, 4, 5}, []int64{2, 3, 5}, 3) + test([]int64{2}, []int64{1, 2, 3, 4}, 1) // only userid 2 + test([]int64{1, 2, 3, 4, 5}, []int64{2, 5}, 2) // userid 2,4 + test([]int64{1, 2, 3, 4, 5}, []int64{2, 3, 5}, 3) // userid 2,4,5 } From 550c4ab0ad648dcf0ed9a4344047f9e70fc0ddea Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 5 Aug 2019 23:56:42 +0800 Subject: [PATCH 3/3] fmt --- models/org_team_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/org_team_test.go b/models/org_team_test.go index d77fea4c46be..06ab4637d8c2 100644 --- a/models/org_team_test.go +++ b/models/org_team_test.go @@ -370,7 +370,7 @@ func TestUsersInTeamsCount(t *testing.T) { assert.Equal(t, expected, count) } - test([]int64{2}, []int64{1, 2, 3, 4}, 1) // only userid 2 - test([]int64{1, 2, 3, 4, 5}, []int64{2, 5}, 2) // userid 2,4 + test([]int64{2}, []int64{1, 2, 3, 4}, 1) // only userid 2 + test([]int64{1, 2, 3, 4, 5}, []int64{2, 5}, 2) // userid 2,4 test([]int64{1, 2, 3, 4, 5}, []int64{2, 3, 5}, 3) // userid 2,4,5 }