Small fixes to manage namespaces

This commit is contained in:
kolaente 2018-07-03 09:09:44 +02:00
parent 064e1cd3b7
commit ac134fb16b
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 15 additions and 12 deletions

View file

@ -5,6 +5,7 @@ import (
"github.com/labstack/echo"
"net/http"
"strconv"
"fmt"
)
func AddNamespace(c echo.Context) error {
@ -117,7 +118,7 @@ func addOrUpdateNamespace(c echo.Context) error {
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
has, err := user.IsNamespaceAdmin(oldNamespace)
has, err := user.IsNamespaceAdmin(&oldNamespace)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
@ -125,6 +126,8 @@ func addOrUpdateNamespace(c echo.Context) error {
return c.JSON(http.StatusForbidden, models.Message{"You need to be namespace admin to edit a namespace."})
}
fmt.Println(namespace)
err = models.CreateOrUpdateNamespace(namespace)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})

View file

@ -38,12 +38,22 @@ func ShowNamespace(c echo.Context) error {
return c.JSON(http.StatusBadRequest, models.Message{"Invalid ID."})
}
// Get the namespace
namespace, err := models.GetNamespaceByID(namespaceID)
if err != nil {
if models.IsErrNamespaceDoesNotExist(err) {
return c.JSON(http.StatusBadRequest, models.Message{"The namespace does not exist."})
}
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
// Check if the user has acces to that namespace
user, err := models.GetCurrentUser(c)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
has, err := user.HasNamespaceAccess(&models.Namespace{ID: namespaceID})
has, err := user.HasNamespaceAccess(&namespace)
if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
@ -51,15 +61,5 @@ func ShowNamespace(c echo.Context) error {
return c.JSON(http.StatusForbidden, models.Message{"You don't have access to this namespace."})
}
// Get the namespace
namespace, err := models.GetNamespaceByID(namespaceID)
if err != nil {
if models.IsErrNamespaceDoesNotExist(err) {
return c.JSON(http.StatusBadRequest, models.Message{"The namespace does not exist."})
}
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
}
return c.JSON(http.StatusOK, namespace)
}