Order the user's organization list alphabetically (#6970)
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6970
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
Otto 2025-02-21 00:42:02 +00:00
commit 8910580d0b
2 changed files with 15 additions and 0 deletions

View file

@ -99,6 +99,7 @@ func GetUserOrgsList(ctx context.Context, user *user_model.User) ([]*MinimalOrg,
if err := db.GetEngine(ctx).Select(columnsStr).
Table("user").
Where(builder.In("`user`.`id`", queryUserOrgIDs(user.ID, true))).
OrderBy("`user`.lower_name ASC").
Find(&orgs); err != nil {
return nil, err
}

View file

@ -4,6 +4,8 @@
package organization_test
import (
"slices"
"strings"
"testing"
"code.gitea.io/gitea/models/db"
@ -74,3 +76,15 @@ func TestGetUserOrgsList(t *testing.T) {
assert.EqualValues(t, 2, orgs[0].NumRepos)
}
}
func TestGetUserOrgsListSorting(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
orgs, err := organization.GetUserOrgsList(db.DefaultContext, &user_model.User{ID: 1})
require.NoError(t, err)
isSorted := slices.IsSortedFunc(orgs, func(a, b *organization.MinimalOrg) int {
return strings.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name))
})
assert.True(t, isSorted)
}