1、action中各动作添加数据权限

2、修改jwt中key为常量
This commit is contained in:
linwenxiang committed 2020-09-03 10:49:31 +08:00
1 parent d3622c93fc
commit 4b8c372038
8 files changed
+54 -16

No files matched your search

+12 -2
View File
@@ -31,13 +31,23 @@ func ViewAction(control dto.Control) gin.HandlerFunc {
var object model.ActiveRecord
object, err = req.GenerateM()
tools.HasError(err, "模型生成失败", 500)
err = db.WithContext(c).First(object).Error
var p = new(dataPermission)
if userId := tools.GetUserIdStr(c); userId != "" {
p, err = newDataPermission(db, userId)
tools.HasError(err, "权限范围鉴定错误", 500)
}
err = db.WithContext(c).Scopes(
Permission(object.TableName(), p),
).First(object).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
tools.HasError(err, "查看失败", 404)
}
tools.HasError(err, "查看失败", 500)
app.OK(c, object, "查看成功")
c.Next()
default:
err = errors.New("db connect not exist")
tools.HasError(err, "", 500)
}
c.Next()
}
}