Fix shared lists showing up twice
This commit is contained in:
parent
156e50f371
commit
67167d4abb
2 changed files with 28 additions and 1 deletions
|
@ -550,6 +550,10 @@ func (n *Namespace) ReadAll(s *xorm.Session, a web.Auth, search string, page int
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, list := range lists {
|
for _, list := range lists {
|
||||||
|
if list.NamespaceID == SharedListsPseudoNamespace.ID {
|
||||||
|
// Shared lists are already in the namespace
|
||||||
|
continue
|
||||||
|
}
|
||||||
namespaces[list.NamespaceID].Lists = append(namespaces[list.NamespaceID].Lists, list)
|
namespaces[list.NamespaceID].Lists = append(namespaces[list.NamespaceID].Lists, list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,7 @@ func TestNamespace_Delete(t *testing.T) {
|
||||||
|
|
||||||
func TestNamespace_ReadAll(t *testing.T) {
|
func TestNamespace_ReadAll(t *testing.T) {
|
||||||
user1 := &user.User{ID: 1}
|
user1 := &user.User{ID: 1}
|
||||||
|
user6 := &user.User{ID: 6}
|
||||||
user7 := &user.User{ID: 7}
|
user7 := &user.User{ID: 7}
|
||||||
user11 := &user.User{ID: 11}
|
user11 := &user.User{ID: 11}
|
||||||
user12 := &user.User{ID: 12}
|
user12 := &user.User{ID: 12}
|
||||||
|
@ -209,7 +210,7 @@ func TestNamespace_ReadAll(t *testing.T) {
|
||||||
namespaces := nn.([]*NamespaceWithLists)
|
namespaces := nn.([]*NamespaceWithLists)
|
||||||
assert.NotNil(t, namespaces)
|
assert.NotNil(t, namespaces)
|
||||||
assert.Len(t, namespaces, 11) // Total of 11 including shared, favorites and saved filters
|
assert.Len(t, namespaces, 11) // Total of 11 including shared, favorites and saved filters
|
||||||
assert.Equal(t, int64(-3), namespaces[0].ID) // The first one should be the one with shared filters
|
assert.Equal(t, int64(-3), namespaces[0].ID) // The first one should be the one with saved filters
|
||||||
assert.Equal(t, int64(-2), namespaces[1].ID) // The second one should be the one with favorites
|
assert.Equal(t, int64(-2), namespaces[1].ID) // The second one should be the one with favorites
|
||||||
assert.Equal(t, int64(-1), namespaces[2].ID) // The third one should be the one with the shared namespaces
|
assert.Equal(t, int64(-1), namespaces[2].ID) // The third one should be the one with the shared namespaces
|
||||||
// Ensure every list and namespace are not archived
|
// Ensure every list and namespace are not archived
|
||||||
|
@ -220,6 +221,28 @@ func TestNamespace_ReadAll(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
t.Run("no own shared lists", func(t *testing.T) {
|
||||||
|
db.LoadAndAssertFixtures(t)
|
||||||
|
s := db.NewSession()
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
n := &Namespace{}
|
||||||
|
nn, _, _, err := n.ReadAll(s, user6, "", 1, -1)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
namespaces := nn.([]*NamespaceWithLists)
|
||||||
|
assert.NotNil(t, namespaces)
|
||||||
|
assert.Equal(t, int64(-1), namespaces[1].ID) // The third one should be the one with the shared namespaces
|
||||||
|
|
||||||
|
sharedListOccurences := make(map[int64]int64)
|
||||||
|
for _, list := range namespaces[1].Lists {
|
||||||
|
assert.NotEqual(t, user1.ID, list.OwnerID)
|
||||||
|
sharedListOccurences[list.ID]++
|
||||||
|
}
|
||||||
|
|
||||||
|
for listID, occ := range sharedListOccurences {
|
||||||
|
assert.Equal(t, int64(1), occ, "shared list %d is present %d times, should be 1", listID, occ)
|
||||||
|
}
|
||||||
|
})
|
||||||
t.Run("namespaces only", func(t *testing.T) {
|
t.Run("namespaces only", func(t *testing.T) {
|
||||||
db.LoadAndAssertFixtures(t)
|
db.LoadAndAssertFixtures(t)
|
||||||
s := db.NewSession()
|
s := db.NewSession()
|
||||||
|
|
Loading…
Reference in a new issue