|
@@ -124,20 +124,24 @@ func AccessAuth(ctx iris.Context) {
|
|
|
}
|
|
|
// 2-2 不容许访问的权限--比对访问路径
|
|
|
requestPath := ctx.Path()
|
|
|
+
|
|
|
+ // 2-3 请求的类型
|
|
|
+ method := ctx.Request().Method
|
|
|
+
|
|
|
// 合同权限
|
|
|
- err = verifyAuth(contractPermission, permissionPath.Contract, requestPath)
|
|
|
+ err = verifyAuth(contractPermission, permissionPath.Contract, requestPath, method)
|
|
|
if err != nil {
|
|
|
ctx.JSON(iris.Map{"code": 2, "msg": fmt.Sprintf("%s", err)})
|
|
|
return
|
|
|
}
|
|
|
// 安全权限
|
|
|
- err = verifyAuth(safePermission, permissionPath.Safe, requestPath)
|
|
|
+ err = verifyAuth(safePermission, permissionPath.Safe, requestPath, method)
|
|
|
if err != nil {
|
|
|
ctx.JSON(iris.Map{"code": 2, "msg": fmt.Sprintf("%s", err)})
|
|
|
return
|
|
|
}
|
|
|
// 质量权限
|
|
|
- err = verifyAuth(qualityPermission, permissionPath.Quality, requestPath)
|
|
|
+ err = verifyAuth(qualityPermission, permissionPath.Quality, requestPath, method)
|
|
|
if err != nil {
|
|
|
ctx.JSON(iris.Map{"code": 2, "msg": fmt.Sprintf("%s", err)})
|
|
|
return
|
|
@@ -156,25 +160,24 @@ func AccessAuth(ctx iris.Context) {
|
|
|
}
|
|
|
|
|
|
// 验证权限路径
|
|
|
-func verifyAuth(permission permission, pathList path, requestPath string) error {
|
|
|
+func verifyAuth(permission permission, pathList path, requestPath string, method string) error {
|
|
|
if permission.Add == 0 {
|
|
|
for _, path := range pathList.Add {
|
|
|
- if path == requestPath {
|
|
|
+ if path == requestPath && method == "POST" {
|
|
|
return errors.New("无权访问")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if permission.Access == 0 {
|
|
|
- fmt.Println(requestPath)
|
|
|
for _, path := range pathList.Access {
|
|
|
- if path == requestPath {
|
|
|
+ if path == requestPath && method == "GET" {
|
|
|
return errors.New("无权访问")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if permission.Delete == 0 {
|
|
|
for _, path := range pathList.Delete {
|
|
|
- if path == requestPath {
|
|
|
+ if path == requestPath && (method == "POST" || method == "DELETE") {
|
|
|
return errors.New("无权访问")
|
|
|
}
|
|
|
}
|