Skip to content

Commit

Permalink
COrrect use UserID in SearchTeams
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Gusted committed Jan 31, 2022
1 parent db7c3ec commit df5a42d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion models/org_team.go
Expand Up @@ -84,10 +84,17 @@ func SearchTeam(opts *SearchTeamOptions) ([]*Team, int64, error) {
cond = cond.And(keywordCond)
}

cond = cond.And(builder.Eq{"org_id": opts.OrgID})
if opts.OrgID > 0 {
cond = cond.And(builder.Eq{"org_id": opts.OrgID})
}

sess := db.GetEngine(db.DefaultContext)

if opts.UserID > 0 {
sess = sess.Join("INNER", "team_user", "team_user.team_id = team.id").
And("team_user.uid=?", opts.UserID)
}

count, err := sess.
Where(cond).
Count(new(Team))
Expand Down

0 comments on commit df5a42d

Please sign in to comment.