2018-07-02 08:54:44 +02:00
|
|
|
package models
|
2018-07-04 08:15:47 +02:00
|
|
|
|
2018-07-12 00:30:31 +02:00
|
|
|
// Update implements the update method via the interface
|
2018-07-21 15:17:02 +02:00
|
|
|
func (n *Namespace) Update() (err error) {
|
2018-07-12 00:30:31 +02:00
|
|
|
// Check if we have at least a name
|
|
|
|
if n.Name == "" {
|
2018-07-21 15:17:02 +02:00
|
|
|
return ErrNamespaceNameCannotBeEmpty{NamespaceID: n.ID}
|
2018-07-04 08:15:47 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 00:30:31 +02:00
|
|
|
// Check if the namespace exists
|
2018-07-21 15:17:02 +02:00
|
|
|
currentNamespace, err := GetNamespaceByID(n.ID)
|
2018-07-04 08:15:47 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-07-12 00:30:31 +02:00
|
|
|
// Check if the (new) owner exists
|
|
|
|
if currentNamespace.OwnerID != n.OwnerID {
|
2018-08-30 19:14:02 +02:00
|
|
|
n.Owner, err = GetUserByID(n.OwnerID)
|
2018-07-12 00:30:31 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2018-07-12 00:09:16 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 00:30:31 +02:00
|
|
|
// Do the actual update
|
|
|
|
_, err = x.ID(currentNamespace.ID).Update(n)
|
2018-07-12 00:09:16 +02:00
|
|
|
return
|
2018-07-12 00:37:31 +02:00
|
|
|
}
|