mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
34 lines
839 B
Go
34 lines
839 B
Go
package simulator
|
|
|
|
import (
|
|
"fmt"
|
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func CheckPermissions(c *gin.Context, modeltype database.ModelName, operation database.CRUD, hasID bool) (bool, Simulator) {
|
|
|
|
var s Simulator
|
|
|
|
err := database.ValidateRole(c, modeltype, operation)
|
|
if err != nil {
|
|
helper.UnprocessableEntityError(c, fmt.Sprintf("Access denied (role validation of simulator failed): %v", err.Error()))
|
|
return false, s
|
|
}
|
|
|
|
if hasID {
|
|
// Get the ID of the simulator from the context
|
|
simulatorID, err := helper.GetIDOfElement(c, "simulatorID", "path", -1)
|
|
if err != nil {
|
|
return false, s
|
|
}
|
|
|
|
err = s.ByID(uint(simulatorID))
|
|
if helper.DBError(c, err) {
|
|
return false, s
|
|
}
|
|
}
|
|
|
|
return true, s
|
|
}
|