41 lines
736 B
Go
41 lines
736 B
Go
package postspolicies
|
|
|
|
import (
|
|
postRules "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
|
|
}
|