0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-11 09:15:31 +02:00

fix: bug where group sort order doesn't update due to duplicate elements in spliced slice

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2026-05-08 21:52:54 -04:00
parent 2fadac8428
commit f5861a3515
No known key found for this signature in database
GPG Key ID: 924A5F6AF051E87C
2 changed files with 19 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting"
@ -434,12 +435,18 @@ func MoveGroup(ctx context.Context, group *Group, newParent int64, newSortOrder
if err = ng.LoadSubgroups(ctx, false); err != nil {
return err
}
siblings = append(append(ng.Subgroups[0:min(newSortOrder, len(ng.Subgroups))], group), ng.Subgroups[newSortOrder:]...)
filtered := container.Filter(ng.Subgroups, func(e *Group) bool {
return e.ID != group.ID
})
siblings = append(append(filtered[0:min(newSortOrder, len(ng.Subgroups))], group), filtered[newSortOrder:]...)
} else if newParent <= 0 {
tmpSiblings, err = FindGroups(ctx, &FindGroupsOptions{
OwnerID: group.OwnerID,
ParentGroupID: 0,
})
tmpSiblings = container.Filter(tmpSiblings, func(e *Group) bool {
return group.ID != e.ID
})
tmpSiblings2 := make(RepoGroupList, newSortOrder)
copy(tmpSiblings2, tmpSiblings[0:newSortOrder])
tmpSiblings2 = append(tmpSiblings2, group)
@ -463,6 +470,7 @@ func MoveGroup(ctx context.Context, group *Group, newParent int64, newSortOrder
group.ParentGroupID = newParent
group.SortOrder = newSortOrder
for i, gg := range siblings {
log.Info("ITEM %+v", gg)
gg.SortOrder = i
if _, err = sess.Table(group.TableName()).
ID(gg.ID).

View File

@ -20,6 +20,16 @@ func FilterSlice[E any, T comparable](s []E, include func(E) (T, bool)) []T {
return slices.Clip(filtered)
}
func Filter[E any](s []E, include func(E) bool) []E {
filtered := make([]E, 0, len(s)) // slice will be clipped before returning
for i := range s {
if ok := include(s[i]); ok {
filtered = append(filtered, s[i])
}
}
return slices.Clip(filtered)
}
func DedupeBy[E any, I comparable](s []E, id func(E) I) []E {
filtered := make([]E, 0, len(s)) // slice will be clipped before returning
seen := make(map[I]bool, len(s))