From ac134fb16b47d0ef3fef7a6f5f15bfd78b5de37f Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 3 Jul 2018 09:09:44 +0200 Subject: [PATCH] Small fixes to manage namespaces --- routes/api/v1/namespace_add_update.go | 5 ++++- routes/api/v1/namespace_show.go | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/routes/api/v1/namespace_add_update.go b/routes/api/v1/namespace_add_update.go index 5009e2ae..511c075c 100644 --- a/routes/api/v1/namespace_add_update.go +++ b/routes/api/v1/namespace_add_update.go @@ -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."}) diff --git a/routes/api/v1/namespace_show.go b/routes/api/v1/namespace_show.go index 95ad363b..649e9f7a 100644 --- a/routes/api/v1/namespace_show.go +++ b/routes/api/v1/namespace_show.go @@ -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) }