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-07-24 17:29:46 +02:00
|
|
|
func (tl *TeamList) ReadAll(user *User) (interface{}, error) {
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
if !l.CanRead(user) {
|
|
|
|
return nil, ErrNeedToHaveListReadAccess{ListID: tl.ListID, UserID: user.ID}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|