2018-09-04 20:15:24 +02:00
|
|
|
package models
|
|
|
|
|
2018-10-31 13:42:38 +01:00
|
|
|
import (
|
|
|
|
"code.vikunja.io/api/pkg/log"
|
|
|
|
)
|
|
|
|
|
2018-09-04 20:15:24 +02:00
|
|
|
// CanCreate checks if the user can create a new user <-> namespace relation
|
|
|
|
func (nu *NamespaceUser) CanCreate(doer *User) bool {
|
|
|
|
// Get the namespace and check if the user has write access on it
|
2018-10-06 13:25:37 +02:00
|
|
|
n, err := GetNamespaceByID(nu.NamespaceID)
|
|
|
|
if err != nil {
|
2018-10-31 13:42:38 +01:00
|
|
|
log.Log.Error("Error occurred during CanCreate for NamespaceUser: %s", err)
|
2018-10-06 13:25:37 +02:00
|
|
|
return false
|
|
|
|
}
|
2018-09-04 20:15:24 +02:00
|
|
|
return n.CanWrite(doer)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CanDelete checks if the user can delete a user <-> namespace relation
|
|
|
|
func (nu *NamespaceUser) CanDelete(doer *User) bool {
|
|
|
|
// Get the namespace and check if the user has write access on it
|
2018-10-06 13:25:37 +02:00
|
|
|
n, err := GetNamespaceByID(nu.NamespaceID)
|
|
|
|
if err != nil {
|
2018-10-31 13:42:38 +01:00
|
|
|
log.Log.Error("Error occurred during CanDelete for NamespaceUser: %s", err)
|
2018-10-06 13:25:37 +02:00
|
|
|
return false
|
|
|
|
}
|
2018-09-04 20:15:24 +02:00
|
|
|
return n.CanWrite(doer)
|
|
|
|
}
|
2018-09-19 08:03:39 +02:00
|
|
|
|
|
|
|
// CanUpdate checks if the user can update a user <-> namespace relation
|
|
|
|
func (nu *NamespaceUser) CanUpdate(doer *User) bool {
|
|
|
|
// Get the namespace and check if the user has write access on it
|
2018-10-06 13:25:37 +02:00
|
|
|
n, err := GetNamespaceByID(nu.NamespaceID)
|
|
|
|
if err != nil {
|
2018-10-31 13:42:38 +01:00
|
|
|
log.Log.Error("Error occurred during CanUpdate for NamespaceUser: %s", err)
|
2018-10-06 13:25:37 +02:00
|
|
|
return false
|
|
|
|
}
|
2018-09-19 08:03:39 +02:00
|
|
|
return n.CanWrite(doer)
|
|
|
|
}
|