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

- move all data and functions solely used for testing to the file test_utilities - get rid of utilities file
43 lines
915 B
Go
43 lines
915 B
Go
package simulator
|
|
|
|
import (
|
|
"fmt"
|
|
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
func checkPermissions(c *gin.Context, modeltype common.ModelName, operation common.CRUD, hasID bool) (bool, Simulator) {
|
|
|
|
var s Simulator
|
|
|
|
err := common.ValidateRole(c, modeltype, operation)
|
|
if err != nil {
|
|
c.JSON(http.StatusUnprocessableEntity, gin.H{
|
|
"success": false,
|
|
"message": fmt.Sprintf("%v", err),
|
|
})
|
|
return false, s
|
|
}
|
|
|
|
if hasID {
|
|
// Get the ID of the simulator from the context
|
|
simulatorID, err := strconv.Atoi(c.Param("simulatorID"))
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
|
"success": false,
|
|
"message": fmt.Sprintf("Could not get simulator's ID from context"),
|
|
})
|
|
return false, s
|
|
}
|
|
|
|
err = s.ByID(uint(simulatorID))
|
|
if common.DBError(c, err) {
|
|
return false, s
|
|
}
|
|
|
|
}
|
|
|
|
return true, s
|
|
}
|