Added Shared lists overview in namespaces (#21)

This commit is contained in:
konrad 2018-11-19 11:37:59 +00:00 committed by Gitea
parent 0c112a0ca3
commit af0ce5bb96
2 changed files with 45 additions and 2 deletions

View file

@ -226,7 +226,7 @@ Teams sind global, d.h. Ein Team kann mehrere Namespaces verwalten.
* [x] Basics
* [x] Reminders
* [ ] 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
* [ ] Testing mit locust: https://locust.io/
* [ ] Methode einbauen, um mit einem gültigen token ein neues gültiges zu kriegen

View file

@ -1,5 +1,7 @@
package models
import "time"
// Namespace holds informations about a namespace
type Namespace struct {
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{}
// 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.*").
Table("namespaces").
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)).
Where("namespaces.name LIKE ?", "%"+search+"%").
Find(&all)
if err != nil {
return all, err
}
@ -133,6 +148,34 @@ func (n *Namespace) ReadAll(search string, doer *User, page int) (interface{}, e
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
AddListDetails(lists)