aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-09-19 14:02:29 +0200
committerGitHub <noreply@github.com>2022-09-19 20:02:29 +0800
commitc5e88fb03d01b929cfcf17c0a817d75572d44023 (patch)
treecab1d3ef10068716a833e6f36f830a34350155df /models
parentc87e6a89da05bcf57cc0b60359915efd008f744f (diff)
downloadgitea-c5e88fb03d01b929cfcf17c0a817d75572d44023.tar.gz
gitea-c5e88fb03d01b929cfcf17c0a817d75572d44023.zip
[API] teamSearch show teams with no members if user is admin (#21204)
close #21176
Diffstat (limited to 'models')
-rw-r--r--models/organization/team.go24
1 files changed, 3 insertions, 21 deletions
diff --git a/models/organization/team.go b/models/organization/team.go
index 2d5ee17272..bd80b1a8c7 100644
--- a/models/organization/team.go
+++ b/models/organization/team.go
@@ -129,29 +129,11 @@ func SearchTeam(opts *SearchTeamOptions) ([]*Team, int64, error) {
if opts.UserID > 0 {
sess = sess.Join("INNER", "team_user", "team_user.team_id = team.id")
}
-
- count, err := sess.
- Where(cond).
- Count(new(Team))
- if err != nil {
- return nil, 0, err
- }
-
- if opts.UserID > 0 {
- sess = sess.Join("INNER", "team_user", "team_user.team_id = team.id")
- }
-
- if opts.PageSize == -1 {
- opts.PageSize = int(count)
- } else {
- sess = sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
- }
+ sess = db.SetSessionPagination(sess, opts)
teams := make([]*Team, 0, opts.PageSize)
- if err = sess.
- Where(cond).
- OrderBy("lower_name").
- Find(&teams); err != nil {
+ count, err := sess.Where(cond).OrderBy("lower_name").FindAndCount(&teams)
+ if err != nil {
return nil, 0, err
}