Skip to content

Commit 7b92f91

Browse files
authored
Fix approvals counting (#7757) (#7777)
* fix approvals counting * fix tests * fmt
1 parent aea49d0 commit 7b92f91

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

models/org_team.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,14 @@ func IsUserInTeams(userID int64, teamIDs []int64) (bool, error) {
755755
}
756756

757757
// UsersInTeamsCount counts the number of users which are in userIDs and teamIDs
758-
func UsersInTeamsCount(userIDs []int64, teamIDs []int64) (count int64, err error) {
759-
if count, err = x.In("uid", userIDs).In("team_id", teamIDs).Count(new(TeamUser)); err != nil {
758+
func UsersInTeamsCount(userIDs []int64, teamIDs []int64) (int64, error) {
759+
var ids []int64
760+
if err := x.In("uid", userIDs).In("team_id", teamIDs).
761+
Table("team_user").
762+
Cols("uid").GroupBy("uid").Find(&ids); err != nil {
760763
return 0, err
761764
}
762-
return
765+
return int64(len(ids)), nil
763766
}
764767

765768
// ___________ __________

models/org_team_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func TestUsersInTeamsCount(t *testing.T) {
370370
assert.Equal(t, expected, count)
371371
}
372372

373-
test([]int64{2}, []int64{1, 2, 3, 4}, 2)
374-
test([]int64{1, 2, 3, 4, 5}, []int64{2, 5}, 2)
375-
test([]int64{1, 2, 3, 4, 5}, []int64{2, 3, 5}, 3)
373+
test([]int64{2}, []int64{1, 2, 3, 4}, 1) // only userid 2
374+
test([]int64{1, 2, 3, 4, 5}, []int64{2, 5}, 2) // userid 2,4
375+
test([]int64{1, 2, 3, 4, 5}, []int64{2, 3, 5}, 3) // userid 2,4,5
376376
}

0 commit comments

Comments
 (0)