mirror of
https://github.com/casdoor/casdoor.git
synced 2025-09-08 12:11:03 +08:00
feat: add parameter v0 for Casbin APIs (#1315)
This commit is contained in:
@@ -21,12 +21,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *ApiController) Enforce() {
|
func (c *ApiController) Enforce() {
|
||||||
userId := c.GetSessionUsername()
|
|
||||||
if userId == "" {
|
|
||||||
c.ResponseError(c.T("EnforcerErr.SignInFirst"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var permissionRule object.PermissionRule
|
var permissionRule object.PermissionRule
|
||||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &permissionRule)
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &permissionRule)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -34,17 +28,11 @@ func (c *ApiController) Enforce() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = object.Enforce(userId, &permissionRule)
|
c.Data["json"] = object.Enforce(&permissionRule)
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ApiController) BatchEnforce() {
|
func (c *ApiController) BatchEnforce() {
|
||||||
userId := c.GetSessionUsername()
|
|
||||||
if userId == "" {
|
|
||||||
c.ResponseError(c.T("EnforcerErr.SignInFirst"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var permissionRules []object.PermissionRule
|
var permissionRules []object.PermissionRule
|
||||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &permissionRules)
|
err := json.Unmarshal(c.Ctx.Input.RequestBody, &permissionRules)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -52,7 +40,7 @@ func (c *ApiController) BatchEnforce() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = object.BatchEnforce(userId, permissionRules)
|
c.Data["json"] = object.BatchEnforce(permissionRules)
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -152,20 +152,20 @@ func removePolicies(permission *Permission) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Enforce(userId string, permissionRule *PermissionRule) bool {
|
func Enforce(permissionRule *PermissionRule) bool {
|
||||||
permission := GetPermission(permissionRule.Id)
|
permission := GetPermission(permissionRule.Id)
|
||||||
enforcer := getEnforcer(permission)
|
enforcer := getEnforcer(permission)
|
||||||
allow, err := enforcer.Enforce(userId, permissionRule.V1, permissionRule.V2)
|
allow, err := enforcer.Enforce(permissionRule.V0, permissionRule.V1, permissionRule.V2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return allow
|
return allow
|
||||||
}
|
}
|
||||||
|
|
||||||
func BatchEnforce(userId string, permissionRules []PermissionRule) []bool {
|
func BatchEnforce(permissionRules []PermissionRule) []bool {
|
||||||
var requests [][]interface{}
|
var requests [][]interface{}
|
||||||
for _, permissionRule := range permissionRules {
|
for _, permissionRule := range permissionRules {
|
||||||
requests = append(requests, []interface{}{userId, permissionRule.V1, permissionRule.V2})
|
requests = append(requests, []interface{}{permissionRule.V0, permissionRule.V1, permissionRule.V2})
|
||||||
}
|
}
|
||||||
permission := GetPermission(permissionRules[0].Id)
|
permission := GetPermission(permissionRules[0].Id)
|
||||||
enforcer := getEnforcer(permission)
|
enforcer := getEnforcer(permission)
|
||||||
|
Reference in New Issue
Block a user