Fix setting a saved filter as favorite
This commit is contained in:
parent
c7f337f303
commit
d9b38b85f6
4 changed files with 46 additions and 19 deletions
|
@ -464,6 +464,10 @@ func addListDetails(s *xorm.Session, lists []*List, a web.Auth) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, list := range lists {
|
for _, list := range lists {
|
||||||
|
// Don't override the favorite state if it was already set from before (favorite saved filters do this)
|
||||||
|
if list.IsFavorite {
|
||||||
|
continue
|
||||||
|
}
|
||||||
list.IsFavorite = favs[list.ID]
|
list.IsFavorite = favs[list.ID]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,6 +640,7 @@ func (l *List) Update(s *xorm.Session, a web.Auth) (err error) {
|
||||||
|
|
||||||
f.Title = l.Title
|
f.Title = l.Title
|
||||||
f.Description = l.Description
|
f.Description = l.Description
|
||||||
|
f.IsFavorite = l.IsFavorite
|
||||||
err = f.Update(s, a)
|
err = f.Update(s, a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -548,7 +548,7 @@ func (n *Namespace) ReadAll(s *xorm.Session, a web.Auth, search string, page int
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////
|
/////////////////
|
||||||
// Add list details (favorite state, among other things
|
// Add list details (favorite state, among other things)
|
||||||
err = addListDetails(s, lists, a)
|
err = addListDetails(s, lists, a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -102,6 +102,7 @@ func (sf *SavedFilter) toList() *List {
|
||||||
Created: sf.Created,
|
Created: sf.Created,
|
||||||
Updated: sf.Updated,
|
Updated: sf.Updated,
|
||||||
Owner: sf.Owner,
|
Owner: sf.Owner,
|
||||||
|
NamespaceID: SavedFiltersPseudoNamespace.ID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,7 @@ func TestSavedFilter_ReadOne(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSavedFilter_Update(t *testing.T) {
|
func TestSavedFilter_Update(t *testing.T) {
|
||||||
|
t.Run("normal", func(t *testing.T) {
|
||||||
db.LoadAndAssertFixtures(t)
|
db.LoadAndAssertFixtures(t)
|
||||||
s := db.NewSession()
|
s := db.NewSession()
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
@ -111,6 +112,26 @@ func TestSavedFilter_Update(t *testing.T) {
|
||||||
"title": "NewTitle",
|
"title": "NewTitle",
|
||||||
"description": "",
|
"description": "",
|
||||||
}, false)
|
}, false)
|
||||||
|
})
|
||||||
|
t.Run("make favorite", func(t *testing.T) {
|
||||||
|
db.LoadAndAssertFixtures(t)
|
||||||
|
s := db.NewSession()
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
sf := &SavedFilter{
|
||||||
|
ID: 1,
|
||||||
|
IsFavorite: true,
|
||||||
|
Filters: &TaskCollection{},
|
||||||
|
}
|
||||||
|
err := sf.Update(s, &user.User{ID: 1})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
err = s.Commit()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
db.AssertExists(t, "saved_filters", map[string]interface{}{
|
||||||
|
"id": 1,
|
||||||
|
"is_favorite": true,
|
||||||
|
}, false)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSavedFilter_Delete(t *testing.T) {
|
func TestSavedFilter_Delete(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue