2018-08-30 08:58:09 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
// ReadAll gets all users who have access to a list
|
|
|
|
func (ul *ListUser) ReadAll(user *User) (interface{}, error) {
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
if !l.CanRead(user) {
|
|
|
|
return nil, ErrNeedToHaveListReadAccess{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all users
|
2018-09-17 19:36:44 +02: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).
|
|
|
|
Find(&all)
|
|
|
|
|
|
|
|
return all, err
|
|
|
|
}
|