VILLASweb-backend-go/routes/simulator/simulator_middleware.go
Sonja Happ 387c922059 Revision of (file) testing
- create a guest user and modify function that adds users to the DB for testing
- improve code coverage of file endpoint tests and remove some obsolete code from file package
- add more error info if role validation fails in all endpoints
- change response of GET files to only return the file data and nothing else
- fix some bugs in file endpoints that became visible by the tests
2019-09-11 12:30:01 +02:00

34 lines
851 B
Go

package simulator
import (
"fmt"
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/database"
"git.rwth-aachen.de/acs/public/villas/villasweb-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
}