From c5e88fb03d01b929cfcf17c0a817d75572d44023 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 19 Sep 2022 14:02:29 +0200 Subject: [API] teamSearch show teams with no members if user is admin (#21204) close #21176 --- models/organization/team.go | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'models') 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 } -- cgit v1.2.3