vikunja-api/models/namespace_users_readall.go

24 lines
568 B
Go
Raw Normal View History

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