mirror of
https://github.com/gogs/gogs.git
synced 2026-07-07 19:23:13 +02:00
models/org_team: getUserTeams uses includes always -1 in the IN statement (#4412)
Ensure that the IN clause contains one value at least. The idea is avoid a
syntax error in the SQL sentence and rollbacks in the transactions.
For example:
ERROR: syntax error at or near ")"
LINE 1: ...RE ... and team.id IN ();
We will always add the -1 value in the IN list.
This commit is contained in:
@@ -450,10 +450,11 @@ func getUserTeams(e Engine, orgID, userID int64) ([]*Team, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
teamIDs := make([]int64, len(teamUsers))
|
||||
teamIDs := make([]int64, len(teamUsers)+1)
|
||||
for i := range teamUsers {
|
||||
teamIDs[i] = teamUsers[i].TeamID
|
||||
}
|
||||
teamIDs[len(teamUsers)] = -1
|
||||
|
||||
teams := make([]*Team, 0, len(teamIDs))
|
||||
return teams, e.Where("org_id = ?", orgID).In("id", teamIDs).Find(&teams)
|
||||
|
||||
Reference in New Issue
Block a user