Files
vikunja/pkg/models/admin_team_list.go
kolaenteandTink 36a2a2e56b fix(admin): rank exact and prefix team matches before the page cap
Same cut-off as the user picker for the invite link team picker.
2026-10-01 17:29:10 +02:00

45 lines
1.6 KiB
Go

// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-present Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package models
import (
"fmt"
"code.vikunja.io/api/pkg/db"
"xorm.io/builder"
"xorm.io/xorm"
)
func (InviteLinkTeam) TableName() string { return "teams" }
func ListTeamsAsAdmin(s *xorm.Session, search string, page, perPage int) ([]InviteLinkTeam, int64, error) {
limit, start := getLimitFromPageIndex(page, perPage)
teams := []InviteLinkTeam{}
cond := builder.Or(builder.IsNull{"external_id"}, builder.Eq{"external_id": ""})
query := s.Limit(limit, start)
if search != "" {
cond = cond.And(db.ILIKE("name", search))
order, args := db.SearchRelevanceOrder(search, "name")
query = query.OrderBy(order, args...)
}
total, err := query.Where(cond).OrderBy("id ASC").FindAndCount(&teams)
if err != nil {
return nil, 0, fmt.Errorf("list invite teams: %w", err)
}
return teams, total, nil
}