diff --git a/routes/api/v1/namespace_add_update.go b/routes/api/v1/namespace_add_update.go index 5009e2aefd9..511c075cc4c 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 95ad363b160..649e9f7a420 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) }