Fix namespaces not found
continuous-integration/drone/pr Build was killed Details

Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
kolaente 2020-12-21 23:38:04 +01:00
parent 9c3f7b7953
commit 2d2463de2f
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 17 additions and 11 deletions

View File

@ -178,6 +178,19 @@ type NamespaceWithLists struct {
Lists []*List `xorm:"-" json:"lists"`
}
func makeNamespaceSliceFromMap(namespaces map[int64]*NamespaceWithLists, userMap map[int64]*user.User) []*NamespaceWithLists {
all := make([]*NamespaceWithLists, 0, len(namespaces))
for _, n := range namespaces {
n.Owner = userMap[n.OwnerID]
all = append(all, n)
}
sort.Slice(all, func(i, j int) bool {
return all[i].ID < all[j].ID
})
return all
}
// ReadAll gets all namespaces a user has access to
// @Summary Get all namespaces a user has access to
// @Description Returns all namespaces a user has access to.
@ -286,18 +299,8 @@ func (n *Namespace) ReadAll(a web.Auth, search string, page int, perPage int) (r
return nil, 0, 0, err
}
//////////////////////
// Put it all together (and sort it)
all := make([]*NamespaceWithLists, 0, len(namespaces))
for _, n := range namespaces {
n.Owner = userMap[n.OwnerID]
all = append(all, n)
}
sort.Slice(all, func(i, j int) bool {
return all[i].ID < all[j].ID
})
if n.NamespacesOnly {
all := makeNamespaceSliceFromMap(namespaces, userMap)
return all, len(all), numberOfTotalItems, nil
}
@ -435,6 +438,9 @@ func (n *Namespace) ReadAll(a web.Auth, search string, page int, perPage int) (r
}
}
//////////////////////
// Put it all together (and sort it)
all := makeNamespaceSliceFromMap(namespaces, userMap)
return all, len(all), numberOfTotalItems, nil
}