vikunja-api/pkg/models/namespace_users_readall.go

23 lines
550 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
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
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
}