Skip to content

Commit c832f0e

Browse files
lunnylafriks
authored andcommitted
Fix approvals counting (#7757)
* fix approvals counting * fix tests * fmt
1 parent 28c5ae2 commit c832f0e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

models/org_team.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -760,11 +760,14 @@ func IsUserInTeams(userID int64, teamIDs []int64) (bool, error) {
760760
}
761761

762762
// UsersInTeamsCount counts the number of users which are in userIDs and teamIDs
763-
func UsersInTeamsCount(userIDs []int64, teamIDs []int64) (count int64, err error) {
764-
if count, err = x.In("uid", userIDs).In("team_id", teamIDs).Count(new(TeamUser)); err != nil {
763+
func UsersInTeamsCount(userIDs []int64, teamIDs []int64) (int64, error) {
764+
var ids []int64
765+
if err := x.In("uid", userIDs).In("team_id", teamIDs).
766+
Table("team_user").
767+
Cols("uid").GroupBy("uid").Find(&ids); err != nil {
765768
return 0, err
766769
}
767-
return
770+
return int64(len(ids)), nil
768771
}
769772

770773
// ___________ __________

models/org_team_test.go

+3-3
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)