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-11-12 16:46:35 +01:00
|
|
|
// @Summary Get teams on a list
|
|
|
|
// @Description Returns a list with all teams which have access on a given list.
|
|
|
|
// @tags sharing
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param id path int true "List ID"
|
|
|
|
// @Param p query int false "The page number. Used for pagination. If not provided, the first page of results is returned."
|
|
|
|
// @Param s query string false "Search teams by its name."
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {array} models.TeamWithRight "The teams with their right."
|
|
|
|
// @Failure 403 {object} models.HTTPError "No right to see the list."
|
|
|
|
// @Failure 500 {object} models.Message "Internal error"
|
|
|
|
// @Router /lists/{id}/teams [get]
|
2018-11-09 18:33:06 +01:00
|
|
|
func (tl *TeamList) ReadAll(search string, u *User, page int) (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-11-12 16:46:35 +01: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).
|
2018-11-09 11:30:17 +01:00
|
|
|
Limit(getLimitFromPageIndex(page)).
|
2018-11-09 18:33:06 +01:00
|
|
|
Where("teams.name LIKE ?", "%"+search+"%").
|
2018-07-24 17:29:46 +02:00
|
|
|
Find(&all)
|
|
|
|
|
|
|
|
return all, err
|
|
|
|
}
|