2018-08-30 08:58:09 +02:00
|
|
|
package models
|
|
|
|
|
2018-10-31 13:42:38 +01:00
|
|
|
import (
|
|
|
|
"code.vikunja.io/api/pkg/log"
|
2018-08-30 08:58:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// CanCreate checks if the user can create a new user <-> list relation
|
|
|
|
func (lu *ListUser) CanCreate(doer *User) bool {
|
|
|
|
// Get the list and check if the user has write access on it
|
2018-10-06 13:05:29 +02:00
|
|
|
l := List{ID: lu.ListID}
|
|
|
|
if err := l.GetSimpleByID(); err != nil {
|
2018-10-31 13:42:38 +01:00
|
|
|
log.Log.Error("Error occurred during CanCreate for ListUser: %s", err)
|
2018-10-06 13:05:29 +02:00
|
|
|
return false
|
|
|
|
}
|
2018-08-30 08:58:09 +02:00
|
|
|
return l.CanWrite(doer)
|
|
|
|
}
|
2018-08-30 18:52:12 +02:00
|
|
|
|
|
|
|
// CanDelete checks if the user can delete a user <-> list relation
|
|
|
|
func (lu *ListUser) CanDelete(doer *User) bool {
|
|
|
|
// Get the list and check if the user has write access on it
|
2018-10-06 13:05:29 +02:00
|
|
|
l := List{ID: lu.ListID}
|
|
|
|
if err := l.GetSimpleByID(); err != nil {
|
2018-10-31 13:42:38 +01:00
|
|
|
log.Log.Error("Error occurred during CanDelete for ListUser: %s", err)
|
2018-10-06 13:05:29 +02:00
|
|
|
return false
|
|
|
|
}
|
2018-08-30 18:52:12 +02:00
|
|
|
return l.CanWrite(doer)
|
|
|
|
}
|
2018-09-19 07:54:47 +02:00
|
|
|
|
|
|
|
// CanUpdate checks if the user can update a user <-> list relation
|
|
|
|
func (lu *ListUser) CanUpdate(doer *User) bool {
|
|
|
|
// Get the list and check if the user has write access on it
|
2018-10-06 13:05:29 +02:00
|
|
|
l := List{ID: lu.ListID}
|
|
|
|
if err := l.GetSimpleByID(); err != nil {
|
2018-10-31 13:42:38 +01:00
|
|
|
log.Log.Error("Error occurred during CanUpdate for ListUser: %s", err)
|
2018-10-06 13:05:29 +02:00
|
|
|
return false
|
|
|
|
}
|
2018-09-19 07:54:47 +02:00
|
|
|
return l.CanWrite(doer)
|
|
|
|
}
|