mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
Renames IsActionAllowed() to ValidateRole()
This commit is contained in:
parent
683ea46b15
commit
e4c8fb9825
2 changed files with 7 additions and 4 deletions
|
@ -91,7 +91,10 @@ func GetWidgetID(c *gin.Context) (int, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsActionAllowed(c *gin.Context, model ModelName, action CRUD) error {
|
func ValidateRole(c *gin.Context, model ModelName, action CRUD) error {
|
||||||
|
// Extracts and validates the role which is saved in the context for
|
||||||
|
// executing a specific CRUD operation on a specific model. In case
|
||||||
|
// of invalid role return an error.
|
||||||
|
|
||||||
// Get user's role from context
|
// Get user's role from context
|
||||||
role, exists := c.Get("user_role")
|
role, exists := c.Get("user_role")
|
||||||
|
|
|
@ -163,7 +163,7 @@ func getUsers(c *gin.Context) {
|
||||||
// @Router /users [post]
|
// @Router /users [post]
|
||||||
func addUser(c *gin.Context) {
|
func addUser(c *gin.Context) {
|
||||||
|
|
||||||
err := common.IsActionAllowed(c, common.ModelUser, common.Create)
|
err := common.ValidateRole(c, common.ModelUser, common.Create)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusUnprocessableEntity, fmt.Sprintf("%v", err))
|
c.JSON(http.StatusUnprocessableEntity, fmt.Sprintf("%v", err))
|
||||||
return
|
return
|
||||||
|
@ -251,7 +251,7 @@ func updateUser(c *gin.Context) {
|
||||||
// @Router /users/{userID} [get]
|
// @Router /users/{userID} [get]
|
||||||
func getUser(c *gin.Context) {
|
func getUser(c *gin.Context) {
|
||||||
|
|
||||||
err := common.IsActionAllowed(c, common.ModelUser, common.Read)
|
err := common.ValidateRole(c, common.ModelUser, common.Read)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusUnprocessableEntity, fmt.Sprintf("%v", err))
|
c.JSON(http.StatusUnprocessableEntity, fmt.Sprintf("%v", err))
|
||||||
return
|
return
|
||||||
|
@ -286,7 +286,7 @@ func getUser(c *gin.Context) {
|
||||||
// @Router /users/{userID} [delete]
|
// @Router /users/{userID} [delete]
|
||||||
func deleteUser(c *gin.Context) {
|
func deleteUser(c *gin.Context) {
|
||||||
|
|
||||||
err := common.IsActionAllowed(c, common.ModelUser, common.Delete)
|
err := common.ValidateRole(c, common.ModelUser, common.Delete)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusUnprocessableEntity, fmt.Sprintf("%v", err))
|
c.JSON(http.StatusUnprocessableEntity, fmt.Sprintf("%v", err))
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue