fix(ui): wrong org dashboard links when switching dashboard context (#8688)

Regression of !8239
Closes #8685

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8688
Reviewed-by: floss4good <floss4good@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Robert Wolff <mahlzahn@posteo.de>
Co-committed-by: Robert Wolff <mahlzahn@posteo.de>
This commit is contained in:
Robert Wolff 2025-08-07 14:32:55 +02:00 committed by Gusted
commit a2b73b7b11
2 changed files with 9 additions and 11 deletions

View file

@ -71,11 +71,8 @@ func GetOrgsCanCreateRepoByUserID(ctx context.Context, userID int64) ([]*Organiz
Find(&orgs)
}
// MinimalOrg represents a simple organization with only the needed columns
type MinimalOrg = Organization
// GetUserOrgsList returns all organizations the given user has access to
func GetUserOrgsList(ctx context.Context, user *user_model.User) ([]*MinimalOrg, error) {
func GetUserOrgsList(ctx context.Context, user *user_model.User) ([]*Organization, error) {
schema, err := db.TableInfo(new(user_model.User))
if err != nil {
return nil, err
@ -100,7 +97,7 @@ func GetUserOrgsList(ctx context.Context, user *user_model.User) ([]*MinimalOrg,
}
columnsStr := selectColumns.String()
var orgs []*MinimalOrg
var orgs []*Organization
if err := db.GetEngine(ctx).Select(columnsStr).
Table("user").
Where(builder.In("`user`.`id`", queryUserOrgIDs(user.ID, true))).
@ -138,6 +135,7 @@ func GetUserOrgsList(ctx context.Context, user *user_model.User) ([]*MinimalOrg,
for _, org := range orgs {
org.NumRepos = orgCountMap[org.ID]
org.Type = user_model.UserTypeOrganization
}
return orgs, nil

View file

@ -85,11 +85,11 @@ func TestGetUserOrgsList(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
orgs, err := organization.GetUserOrgsList(db.DefaultContext, &user_model.User{ID: 4})
require.NoError(t, err)
if assert.Len(t, orgs, 1) {
assert.EqualValues(t, 3, orgs[0].ID)
// repo_id: 3 is in the team, 32 is public, 5 is private with no team
assert.Equal(t, 2, orgs[0].NumRepos)
}
assert.Len(t, orgs, 1)
assert.EqualValues(t, 3, orgs[0].ID)
// repo_id: 3 is in the team, 32 is public, 5 is private with no team
assert.Equal(t, 2, orgs[0].NumRepos)
assert.Equal(t, user_model.UserTypeOrganization, orgs[0].Type)
}
func TestGetUserOrgsListSorting(t *testing.T) {
@ -97,7 +97,7 @@ func TestGetUserOrgsListSorting(t *testing.T) {
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 {
isSorted := slices.IsSortedFunc(orgs, func(a, b *organization.Organization) int {
return strings.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name))
})