1
0

Added logging

This commit is contained in:
kolaente
2018-09-19 08:35:53 +02:00
parent 091711f4c5
commit e93cba7108
24 changed files with 1596 additions and 10 deletions

View File

@ -26,12 +26,15 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
// Check rights
if !c.CObject.CanCreate(&currentUser) {
models.Log.Noticef("%s [ID: %d] tried to create while not having the rights for it", currentUser.Username, currentUser.ID)
return echo.NewHTTPError(http.StatusForbidden)
}
// Create
err = c.CObject.Create(&currentUser)
if err != nil {
models.Log.Error(err.Error())
if models.IsErrListDoesNotExist(err) {
return echo.NewHTTPError(http.StatusBadRequest, "The list does not exist.")
}

View File

@ -19,11 +19,14 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError)
}
if !c.CObject.CanDelete(&user) {
models.Log.Noticef("%s [ID: %d] tried to delete while not having the rights for it", user.Username, user.ID)
return echo.NewHTTPError(http.StatusForbidden)
}
err = c.CObject.Delete()
if err != nil {
models.Log.Error(err.Error())
if models.IsErrNeedToBeListAdmin(err) {
return echo.NewHTTPError(http.StatusForbidden, "You need to be the list admin to delete a list.")
}

View File

@ -20,6 +20,8 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
lists, err := c.CObject.ReadAll(&currentUser)
if err != nil {
models.Log.Error(err.Error())
if models.IsErrNeedToHaveListReadAccess(err) {
return echo.NewHTTPError(http.StatusForbidden, "You need to have read access to this list.")
}

View File

@ -2,7 +2,6 @@ package crud
import (
"code.vikunja.io/api/models"
"fmt"
"github.com/labstack/echo"
"net/http"
)
@ -18,6 +17,8 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
// Get our object
err := c.CObject.ReadOne()
if err != nil {
models.Log.Error(err.Error())
if models.IsErrListDoesNotExist(err) {
return echo.NewHTTPError(http.StatusNotFound)
}
@ -30,8 +31,6 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusNotFound)
}
fmt.Println(err)
return echo.NewHTTPError(http.StatusInternalServerError, "An error occured.")
}
@ -42,6 +41,7 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
}
if !c.CObject.CanRead(&currentUser) {
models.Log.Noticef("%s [ID: %d] tried to read while not having the rights for it", currentUser.Username, currentUser.ID)
return echo.NewHTTPError(http.StatusForbidden, "You don't have the right to see this")
}

View File

@ -24,12 +24,15 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
}
if !c.CObject.CanUpdate(&currentUser) {
models.Log.Noticef("%s [ID: %d] tried to update while not having the rights for it", currentUser.Username, currentUser.ID)
return echo.NewHTTPError(http.StatusForbidden)
}
// Do the update
err = c.CObject.Update()
if err != nil {
models.Log.Error(err.Error())
if models.IsErrNeedToBeListAdmin(err) {
return echo.NewHTTPError(http.StatusForbidden, "You need to be list admin to do that.")
}