Fix getting lists for shared, favorite and saved lists namespace

This commit is contained in:
kolaente 2021-03-18 21:39:38 +01:00
parent fc4eb8ceb9
commit 6fa95e6492
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
3 changed files with 44 additions and 15 deletions

View file

@ -102,20 +102,42 @@ var FavoritesPseudoList = List{
// GetListsByNamespaceID gets all lists in a namespace
func GetListsByNamespaceID(s *xorm.Session, nID int64, doer *user.User) (lists []*List, err error) {
if nID == -1 {
err = s.Select("l.*").
Table("list").
Join("LEFT", []string{"team_list", "tl"}, "l.id = tl.list_id").
Join("LEFT", []string{"team_members", "tm"}, "tm.team_id = tl.team_id").
Join("LEFT", []string{"users_list", "ul"}, "ul.list_id = l.id").
Join("LEFT", []string{"namespaces", "n"}, "l.namespace_id = n.id").
Where("tm.user_id = ?", doer.ID).
Where("l.is_archived = false").
Where("n.is_archived = false").
Or("ul.user_id = ?", doer.ID).
GroupBy("l.id").
Find(&lists)
} else {
switch nID {
case SharedListsPseudoNamespace.ID:
nnn, err := getSharedListsInNamespace(s, false, doer)
if err != nil {
return nil, err
}
if nnn != nil && nnn.Lists != nil {
lists = nnn.Lists
}
case FavoritesPseudoNamespace.ID:
namespaces := make(map[int64]*NamespaceWithLists)
_, err := getNamespacesWithLists(s, &namespaces, "", false, 0, -1, doer.ID)
if err != nil {
return nil, err
}
namespaceIDs, _ := getNamespaceOwnerIDs(namespaces)
ls, err := getListsForNamespaces(s, namespaceIDs, false)
if err != nil {
return nil, err
}
nnn, err := getFavoriteLists(s, ls, namespaceIDs, doer)
if err != nil {
return nil, err
}
if nnn != nil && nnn.Lists != nil {
lists = nnn.Lists
}
case SavedFiltersPseudoNamespace.ID:
nnn, err := getSavedFilters(s, doer)
if err != nil {
return nil, err
}
if nnn != nil && nnn.Lists != nil {
lists = nnn.Lists
}
default:
err = s.Select("l.*").
Alias("l").
Join("LEFT", []string{"namespaces", "n"}, "l.namespace_id = n.id").

View file

@ -113,6 +113,10 @@ func getNamespaceSimpleByID(s *xorm.Session, id int64) (namespace *Namespace, er
return &FavoritesPseudoNamespace, nil
}
if id == SavedFiltersPseudoNamespace.ID {
return &SavedFiltersPseudoNamespace, nil
}
namespace = &Namespace{}
exists, err := s.Where("id = ?", id).Get(namespace)

View file

@ -72,7 +72,10 @@ func (n *Namespace) checkRight(s *xorm.Session, a web.Auth, rights ...Right) (bo
return false, 0, err
}
if a.GetID() == nn.OwnerID {
if a.GetID() == nn.OwnerID ||
nn.ID == SharedListsPseudoNamespace.ID ||
nn.ID == FavoritesPseudoNamespace.ID ||
nn.ID == SavedFiltersPseudoNamespace.ID {
return true, int(RightAdmin), nil
}