Small fixes to manage namespaces
This commit is contained in:
@ -1,14 +1,14 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"strconv"
|
||||
"net/http"
|
||||
"git.kolaente.de/konrad/list/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetListsByNamespaceID(c echo.Context) error {
|
||||
// swagger:operation GET /namespaces/{namespaceID}/lists namespaces getNamespaces
|
||||
// swagger:operation GET /namespaces/{namespaceID}/lists namespaces getListsByNamespace
|
||||
// ---
|
||||
// summary: gets all lists belonging to that namespace
|
||||
// consumes:
|
||||
@ -29,8 +29,6 @@ func GetListsByNamespaceID(c echo.Context) error {
|
||||
// "500":
|
||||
// "$ref": "#/responses/Message"
|
||||
|
||||
|
||||
|
||||
// Check if we have our ID
|
||||
id := c.Param("id")
|
||||
// Make int
|
||||
@ -45,7 +43,7 @@ func GetListsByNamespaceID(c echo.Context) error {
|
||||
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(&models.Namespace{ID: namespaceID})
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
|
||||
}
|
||||
@ -65,4 +63,4 @@ func GetListsByNamespaceID(c echo.Context) error {
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, lists)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -43,7 +43,7 @@ func ShowNamespace(c echo.Context) error {
|
||||
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(&models.Namespace{ID: namespaceID})
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"An error occured."})
|
||||
}
|
||||
|
@ -19,4 +19,7 @@ type swaggerParameterBodies struct {
|
||||
|
||||
// in:body
|
||||
ListItem models.ListItem
|
||||
|
||||
// in:body
|
||||
Namespace models.Namespace
|
||||
}
|
||||
|
@ -50,3 +50,14 @@ type swaggerResponseLIstItem struct {
|
||||
// in:body
|
||||
Body models.ListItem `json:"body"`
|
||||
}
|
||||
|
||||
// ================
|
||||
// Namespace definitions
|
||||
// ================
|
||||
|
||||
// Namespace
|
||||
// swagger:response Namespace
|
||||
type swaggerResponseNamespace struct {
|
||||
// in:body
|
||||
Body models.Namespace `json:"body"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user