mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00

- revise documentation for swaggo - clean up testdata, serializers and responses - add validators for signal endpoints - revise signal endpoint implementations
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package signal
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
|
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulationmodel"
|
|
)
|
|
|
|
func checkPermissions(c *gin.Context, operation common.CRUD) (bool, Signal) {
|
|
|
|
var sig Signal
|
|
|
|
err := common.ValidateRole(c, common.ModelSignal, operation)
|
|
if err != nil {
|
|
c.JSON(http.StatusUnprocessableEntity, gin.H{
|
|
"success": false,
|
|
"message": fmt.Sprintf("Access denied (role validation failed): %v", err),
|
|
})
|
|
return false, sig
|
|
}
|
|
|
|
signalID, err := strconv.Atoi(c.Param("signalID"))
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
|
"success": false,
|
|
"error": fmt.Sprintf("Bad request. No or incorrect format of signalID path parameter"),
|
|
})
|
|
return false, sig
|
|
}
|
|
|
|
err = sig.byID(uint(signalID))
|
|
if common.ProvideErrorResponse(c, err) {
|
|
return false, sig
|
|
}
|
|
|
|
ok, _ := simulationmodel.CheckPermissions(c, operation, "body", int(sig.SimulationModelID))
|
|
if !ok {
|
|
return false, sig
|
|
}
|
|
|
|
return true, sig
|
|
}
|