Skip to content

Commit

Permalink
Fix approvals counting (go-gitea#7757)
Browse files Browse the repository at this point in the history
* fix approvals counting

* fix tests

* fmt
  • Loading branch information
lunny committed Aug 7, 2019
1 parent aea49d0 commit 854e0c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions models/org_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,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
}

// ___________ __________
Expand Down
6 changes: 3 additions & 3 deletions models/org_team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 854e0c0

Please sign in to comment.