diff --git a/pkg/models/list.go b/pkg/models/list.go index 2148e84b..61d4ebe8 100644 --- a/pkg/models/list.go +++ b/pkg/models/list.go @@ -464,6 +464,10 @@ func addListDetails(s *xorm.Session, lists []*List, a web.Auth) (err error) { } 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] } @@ -636,6 +640,7 @@ func (l *List) Update(s *xorm.Session, a web.Auth) (err error) { f.Title = l.Title f.Description = l.Description + f.IsFavorite = l.IsFavorite err = f.Update(s, a) if err != nil { return err diff --git a/pkg/models/namespace.go b/pkg/models/namespace.go index 3858ee3a..04f2bad6 100644 --- a/pkg/models/namespace.go +++ b/pkg/models/namespace.go @@ -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) if err != nil { return diff --git a/pkg/models/saved_filters.go b/pkg/models/saved_filters.go index 35972b7e..89f24671 100644 --- a/pkg/models/saved_filters.go +++ b/pkg/models/saved_filters.go @@ -102,6 +102,7 @@ func (sf *SavedFilter) toList() *List { Created: sf.Created, Updated: sf.Updated, Owner: sf.Owner, + NamespaceID: SavedFiltersPseudoNamespace.ID, } } diff --git a/pkg/models/saved_filters_test.go b/pkg/models/saved_filters_test.go index f0256203..f72031c2 100644 --- a/pkg/models/saved_filters_test.go +++ b/pkg/models/saved_filters_test.go @@ -92,25 +92,46 @@ func TestSavedFilter_ReadOne(t *testing.T) { } func TestSavedFilter_Update(t *testing.T) { - db.LoadAndAssertFixtures(t) - s := db.NewSession() - defer s.Close() + t.Run("normal", func(t *testing.T) { + db.LoadAndAssertFixtures(t) + s := db.NewSession() + defer s.Close() - sf := &SavedFilter{ - ID: 1, - Title: "NewTitle", - Description: "", // Explicitly reset the description - 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, - "title": "NewTitle", - "description": "", - }, false) + sf := &SavedFilter{ + ID: 1, + Title: "NewTitle", + Description: "", // Explicitly reset the description + 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, + "title": "NewTitle", + "description": "", + }, 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) {