2024-11-16 18:04:33 +03:00

41 lines
726 B
Go

package postspolicies
import (
"enshi/ABAC/PostsPolicies/postRules"
"enshi/ABAC/rules"
"github.com/gin-gonic/gin"
)
const (
DELETE_POST = "delete_post"
UPDATE_POST = "update_post"
CREATE_POST = "create_post"
GET_POST = "get_post"
)
func PostsPolicies(c *gin.Context) (bool, []error) {
target, exists := c.Get("target")
if !exists {
return false, nil
}
// Permit if one permit
switch target {
case DELETE_POST:
return rules.CheckRule(c, postRules.DeleteRule)
case UPDATE_POST:
return rules.CheckRule(c, postRules.PostUpdateRule)
case GET_POST:
return rules.CheckRule(c, postRules.PostReadRule)
case CREATE_POST:
return rules.CheckRule(c, postRules.PostCreateRule)
}
return false, nil
}