【无权限拦截】

This commit is contained in:
weizhihong 2023-08-30 14:26:48 +08:00
parent 78c81a9228
commit a373c33bc6
3 changed files with 4 additions and 3 deletions

View File

@ -12,4 +12,6 @@ const (
// DataOperationError 数据操作错误(增删改查操作出了意料之外的错误都算) // DataOperationError 数据操作错误(增删改查操作出了意料之外的错误都算)
DataOperationError = 2002 DataOperationError = 2002
ArgumentParseError = 3000 ArgumentParseError = 3000
NoAuthOperationError = 4001
) )

View File

@ -1,7 +1,6 @@
package middleware package middleware
import ( import (
"net/http"
"strings" "strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -39,7 +38,7 @@ func permissionMiddleware() gin.HandlerFunc {
if isVaild { // 用户有权限 if isVaild { // 用户有权限
c.Next() c.Next()
} else { } else {
c.JSON(http.StatusUnauthorized, "无权限访问") panic(dto.ErrorDto{Code: dto.NoAuthOperationError, Message: "无权限操作"})
} }
} }
} }

View File

@ -57,7 +57,7 @@ func PublishFormDraft(req *publishedGi.PublishReqDto, user *model.User) {
} }
//需要删除的同名数据 //需要删除的同名数据
oldData, _ := dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Name.Eq(req.Name)).Find() oldData, _ := dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Name.Eq(req.Name)).Find()
if oldData != nil && len(oldData) > 0 { if len(oldData) > 0 {
// 逻辑删除 // 逻辑删除
dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Name.Eq(req.Name)).UpdateColumn(dbquery.PublishedGi.Status, 0) dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Name.Eq(req.Name)).UpdateColumn(dbquery.PublishedGi.Status, 0)
for _, v := range oldData { for _, v := range oldData {