2018-09-04 20:15:24 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
// ReadAll gets all users who have access to a namespace
|
2018-10-31 13:42:38 +01:00
|
|
|
func (un *NamespaceUser) ReadAll(u *User) (interface{}, error) {
|
2018-09-04 20:15:24 +02:00
|
|
|
// Check if the user has access to the namespace
|
|
|
|
l, err := GetNamespaceByID(un.NamespaceID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-10-31 13:42:38 +01:00
|
|
|
if !l.CanRead(u) {
|
2018-09-04 20:15:24 +02:00
|
|
|
return nil, ErrNeedToHaveNamespaceReadAccess{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all users
|
2018-09-17 19:39:14 +02:00
|
|
|
all := []*userWithRight{}
|
2018-09-04 20:15:24 +02:00
|
|
|
err = x.
|
|
|
|
Join("INNER", "users_namespace", "user_id = users.id").
|
|
|
|
Where("users_namespace.namespace_id = ?", un.NamespaceID).
|
|
|
|
Find(&all)
|
|
|
|
|
|
|
|
return all, err
|
|
|
|
}
|