123456789101112131415161718192021222324252627282930 |
- package actions
- import (
- "github.com/beego/beego/v2/server/web/context"
- "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/beegouser"
- "gorm.io/gorm"
- )
- type DataPermission struct {
- UserId int
- DeptId int
- }
- func Permission(tableName string, p *DataPermission) func(db *gorm.DB) *gorm.DB {
- return func(db *gorm.DB) *gorm.DB {
- return db.Where(tableName+".dept_id = ? ", p.DeptId)
- }
- }
- func getPermissionFromContext(c *context.Context) *DataPermission {
- p := new(DataPermission)
- p.UserId = beegouser.GetUserId(c)
- p.DeptId = beegouser.GetDeptId(c)
- return p
- }
- // GetPermissionFromContext 提供非action写法数据范围约束
- func GetPermissionFromContext(c *context.Context) *DataPermission {
- return getPermissionFromContext(c)
- }
|