Added Shared lists overview in namespaces (#21)
This commit is contained in:
parent
0c112a0ca3
commit
af0ce5bb96
2 changed files with 45 additions and 2 deletions
|
@ -226,7 +226,7 @@ Teams sind global, d.h. Ein Team kann mehrere Namespaces verwalten.
|
||||||
* [x] Basics
|
* [x] Basics
|
||||||
* [x] Reminders
|
* [x] Reminders
|
||||||
* [ ] Discovery, stichwort PROPFIND
|
* [ ] Discovery, stichwort PROPFIND
|
||||||
* [ ] Wir brauchen noch ne gute idee, wie man die listen kriegt, auf die man nur so Zugriff hat (ohne namespace)
|
* [x] Wir brauchen noch ne gute idee, wie man die listen kriegt, auf die man nur so Zugriff hat (ohne namespace)
|
||||||
* Dazu am Besten nen pseudonamespace anlegen (id -1 oder so), der hat das dann alles
|
* Dazu am Besten nen pseudonamespace anlegen (id -1 oder so), der hat das dann alles
|
||||||
* [ ] Testing mit locust: https://locust.io/
|
* [ ] Testing mit locust: https://locust.io/
|
||||||
* [ ] Methode einbauen, um mit einem gültigen token ein neues gültiges zu kriegen
|
* [ ] Methode einbauen, um mit einem gültigen token ein neues gültiges zu kriegen
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
// Namespace holds informations about a namespace
|
// Namespace holds informations about a namespace
|
||||||
type Namespace struct {
|
type Namespace struct {
|
||||||
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"namespace"`
|
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"namespace"`
|
||||||
|
@ -85,6 +87,20 @@ func (n *Namespace) ReadAll(search string, doer *User, page int) (interface{}, e
|
||||||
|
|
||||||
all := []*NamespaceWithLists{}
|
all := []*NamespaceWithLists{}
|
||||||
|
|
||||||
|
// Create our pseudo-namespace to hold the shared lists
|
||||||
|
// We want this one at the beginning, which is why we create it here
|
||||||
|
all = append(all, &NamespaceWithLists{
|
||||||
|
Namespace{
|
||||||
|
ID: -1,
|
||||||
|
Name: "Shared Lists",
|
||||||
|
Description: "Lists of other users shared with you via teams or directly.",
|
||||||
|
Owner: *doer,
|
||||||
|
Created: time.Now().Unix(),
|
||||||
|
Updated: time.Now().Unix(),
|
||||||
|
},
|
||||||
|
[]*List{},
|
||||||
|
})
|
||||||
|
|
||||||
err := x.Select("namespaces.*").
|
err := x.Select("namespaces.*").
|
||||||
Table("namespaces").
|
Table("namespaces").
|
||||||
Join("LEFT", "team_namespaces", "namespaces.id = team_namespaces.namespace_id").
|
Join("LEFT", "team_namespaces", "namespaces.id = team_namespaces.namespace_id").
|
||||||
|
@ -97,7 +113,6 @@ func (n *Namespace) ReadAll(search string, doer *User, page int) (interface{}, e
|
||||||
Limit(getLimitFromPageIndex(page)).
|
Limit(getLimitFromPageIndex(page)).
|
||||||
Where("namespaces.name LIKE ?", "%"+search+"%").
|
Where("namespaces.name LIKE ?", "%"+search+"%").
|
||||||
Find(&all)
|
Find(&all)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return all, err
|
return all, err
|
||||||
}
|
}
|
||||||
|
@ -133,6 +148,34 @@ func (n *Namespace) ReadAll(search string, doer *User, page int) (interface{}, e
|
||||||
return all, err
|
return all, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get all lists individually shared with our user (not via a namespace)
|
||||||
|
individualLists := []*List{}
|
||||||
|
err = x.Select("l.*").
|
||||||
|
Table("list").
|
||||||
|
Alias("l").
|
||||||
|
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").
|
||||||
|
Where("tm.user_id = ?", doer.ID).
|
||||||
|
Or("ul.user_id = ?", doer.ID).
|
||||||
|
GroupBy("l.id").
|
||||||
|
Find(&individualLists)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the namespace -1 so we now later which one it was
|
||||||
|
// + Append it to all lists we already have
|
||||||
|
for _, l := range individualLists {
|
||||||
|
l.NamespaceID = -1
|
||||||
|
lists = append(lists, l)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the pseudonamespace if we don't have any shared lists
|
||||||
|
if len(individualLists) == 0 {
|
||||||
|
all = append(all[:0], all[1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
// More details for the lists
|
// More details for the lists
|
||||||
AddListDetails(lists)
|
AddListDetails(lists)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue