1
0

Small fixes to manage namespaces

This commit is contained in:
kolaente
2018-07-03 08:48:28 +02:00
parent e0244e28d7
commit 064e1cd3b7
8 changed files with 116 additions and 17 deletions

View File

@ -112,13 +112,17 @@ func addOrUpdateNamespace(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
} else {
// Check if the user owns the namespace
// Check if the user has admin access to the namespace
oldNamespace, err := models.GetNamespaceByID(namespace.ID)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
if user.ID != oldNamespace.Owner.ID {
return c.JSON(http.StatusForbidden, models.Message{"You cannot edit a namespace you don't own."})
has, err := user.IsNamespaceAdmin(oldNamespace)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
if !has {
return c.JSON(http.StatusForbidden, models.Message{"You need to be namespace admin to edit a namespace."})
}
err = models.CreateOrUpdateNamespace(namespace)