api/pkg/models/namespace_users_readall.go

23 lines
550 B
Go
Raw Normal View History

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