Skip to content

Commit df5a42d

Browse files
author
Gusted
committed
COrrect use UserID in SearchTeams
- Use `UserID` in the `SearchTeams` function, currently it was useless to pass such information. Now it does a INNER statement to `team_user` which obtains UserID -> TeamID data. - Make OrgID optional. - Resolves go-gitea#18484
1 parent db7c3ec commit df5a42d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

models/org_team.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,17 @@ func SearchTeam(opts *SearchTeamOptions) ([]*Team, int64, error) {
8484
cond = cond.And(keywordCond)
8585
}
8686

87-
cond = cond.And(builder.Eq{"org_id": opts.OrgID})
87+
if opts.OrgID > 0 {
88+
cond = cond.And(builder.Eq{"org_id": opts.OrgID})
89+
}
8890

8991
sess := db.GetEngine(db.DefaultContext)
9092

93+
if opts.UserID > 0 {
94+
sess = sess.Join("INNER", "team_user", "team_user.team_id = team.id").
95+
And("team_user.uid=?", opts.UserID)
96+
}
97+
9198
count, err := sess.
9299
Where(cond).
93100
Count(new(Team))

0 commit comments

Comments
 (0)