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