2018-07-24 17:29:46 +02:00
|
|
|
package models
|
|
|
|
|
2018-08-29 08:50:52 +02:00
|
|
|
// ReadAll implements the method to read all teams of a list
|
2018-10-31 13:42:38 +01:00
|
|
|
func (tl *TeamList) ReadAll(u *User) (interface{}, error) {
|
2018-07-24 17:29:46 +02:00
|
|
|
// Check if the user can read the namespace
|
2018-10-06 13:05:29 +02:00
|
|
|
l := &List{ID: tl.ListID}
|
|
|
|
if err := l.GetSimpleByID(); err != nil {
|
2018-07-24 17:29:46 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
2018-10-31 13:42:38 +01:00
|
|
|
if !l.CanRead(u) {
|
|
|
|
return nil, ErrNeedToHaveListReadAccess{ListID: tl.ListID, UserID: u.ID}
|
2018-07-24 17:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the teams
|
2018-09-17 19:45:18 +02:00
|
|
|
all := []*teamWithRight{}
|
2018-10-06 13:05:29 +02:00
|
|
|
err := x.
|
2018-07-24 17:29:46 +02:00
|
|
|
Table("teams").
|
|
|
|
Join("INNER", "team_list", "team_id = teams.id").
|
|
|
|
Where("team_list.list_id = ?", tl.ListID).
|
|
|
|
Find(&all)
|
|
|
|
|
|
|
|
return all, err
|
|
|
|
}
|