2018-08-30 08:58:09 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
// ReadAll gets all users who have access to a list
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Summary Get users on a list
|
|
|
|
// @Description Returns a list with all users 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 users by its name."
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {array} models.UserWithRight "The users with the right they have."
|
|
|
|
// @Failure 403 {object} models.HTTPError "No right to see the list."
|
|
|
|
// @Failure 500 {object} models.Message "Internal error"
|
|
|
|
// @Router /lists/{id}/users [get]
|
2018-11-09 18:33:06 +01:00
|
|
|
func (ul *ListUser) ReadAll(search string, u *User, page int) (interface{}, error) {
|
2018-08-30 08:58:09 +02:00
|
|
|
// Check if the user has access to the list
|
2018-10-06 13:05:29 +02:00
|
|
|
l := &List{ID: ul.ListID}
|
|
|
|
if err := l.GetSimpleByID(); err != nil {
|
2018-08-30 08:58:09 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
2018-10-31 13:42:38 +01:00
|
|
|
if !l.CanRead(u) {
|
2018-08-30 08:58:09 +02:00
|
|
|
return nil, ErrNeedToHaveListReadAccess{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all users
|
2018-11-12 16:46:35 +01:00
|
|
|
all := []*UserWithRight{}
|
2018-10-06 13:05:29 +02:00
|
|
|
err := x.
|
2018-08-30 08:58:09 +02:00
|
|
|
Join("INNER", "users_list", "user_id = users.id").
|
|
|
|
Where("users_list.list_id = ?", ul.ListID).
|
2018-11-09 11:30:17 +01:00
|
|
|
Limit(getLimitFromPageIndex(page)).
|
2018-11-09 18:33:06 +01:00
|
|
|
Where("users.username LIKE ?", "%"+search+"%").
|
2018-08-30 08:58:09 +02:00
|
|
|
Find(&all)
|
|
|
|
|
|
|
|
return all, err
|
|
|
|
}
|