1
0

Make sure list / task favorites are set per user, not per entity (#915)

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/915
Co-authored-by: konrad <konrad@kola-entertainments.de>
Co-committed-by: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad
2021-07-10 10:21:54 +00:00
parent 373e3f3d60
commit d0c77ad1c1
16 changed files with 409 additions and 53 deletions

View File

@ -392,12 +392,21 @@ func getFavoriteLists(s *xorm.Session, lists []*List, namespaceIDs []int64, doer
}
// Check if we have any favorites or favorited lists and remove the favorites namespace from the list if not
var favoriteCount int64
favoriteCount, err = s.
cond := builder.
Select("tasks.id").
From("tasks").
Join("INNER", "lists", "tasks.list_id = lists.id").
Join("INNER", "namespaces", "lists.namespace_id = namespaces.id").
Where(builder.And(builder.Eq{"tasks.is_favorite": true}, builder.In("namespaces.id", namespaceIDs))).
Count(&Task{})
Where(builder.In("namespaces.id", namespaceIDs))
var favoriteCount int64
favoriteCount, err = s.
Where(builder.And(
builder.Eq{"user_id": doer.ID},
builder.Eq{"kind": FavoriteKindTask},
builder.In("entity_id", cond),
)).
Count(&Favorite{})
if err != nil {
return
}
@ -538,6 +547,13 @@ func (n *Namespace) ReadAll(s *xorm.Session, a web.Auth, search string, page int
lists = append(lists, savedFiltersNamespace.Lists...)
}
/////////////////
// Add list details (favorite state, among other things
err = addListDetails(s, lists, a)
if err != nil {
return
}
/////////////////
// Favorite lists
@ -553,11 +569,6 @@ func (n *Namespace) ReadAll(s *xorm.Session, a web.Auth, search string, page int
//////////////////////
// Put it all together
err = addListDetails(s, lists)
if err != nil {
return
}
for _, list := range lists {
if list.NamespaceID == SharedListsPseudoNamespace.ID || list.NamespaceID == SavedFiltersPseudoNamespace.ID {
// Shared lists and filtered lists are already in the namespace