fix 完善数据权限验证

This commit is contained in:
yxh 2023-02-08 09:12:43 +08:00
parent 8238ed6753
commit 10ed960475
3 changed files with 18 additions and 1 deletions

View File

@ -237,6 +237,8 @@ func (s *sSysRole) RoleDataScope(ctx context.Context, req *system.DataScopeReq)
_, err = tx.Model(dao.SysRoleDept.Table()).Data(data).Insert()
liberr.ErrIsNil(ctx, err, "设置失败")
}
//清除缓存
commonService.Cache().Remove(ctx, consts.CacheSysRole)
})
return err
})

View File

@ -678,7 +678,7 @@ func (s *sSysUser) GetDataWhere(ctx context.Context, userInfo *model.ContextUser
}
dList = append(dList, m)
}
l := libUtils.FindSonByParentId(dList, gconv.Int(userInfo.DeptId), "pid", "id")
l := libUtils.FindSonByParentId(dList, userInfo.DeptId, "pid", "id")
for _, li := range l {
deptIdArr.Add(gconv.Int64(li["id"]))
}
@ -695,3 +695,17 @@ func (s *sSysUser) GetDataWhere(ctx context.Context, userInfo *model.ContextUser
}
return
}
// HasAccessByDataWhere 判断用户是否有数据权限
func (s *sSysUser) HasAccessByDataWhere(ctx context.Context, where g.Map, uid interface{}) bool {
err := g.Try(ctx, func(ctx context.Context) {
rec, err := dao.SysUser.Ctx(ctx).As("user").
Fields("user.id").
Where("user.id",uid).Where(where).One()
liberr.ErrIsNil(ctx, err)
if rec.IsEmpty() {
liberr.ErrIsNil(ctx, gerror.New("没有数据"))
}
})
return err == nil
}

View File

@ -46,6 +46,7 @@ type (
Delete(ctx context.Context, ids []int) (err error)
GetUsers(ctx context.Context, ids []int) (users []*model.SysUserSimpleRes, err error)
GetDataWhere(ctx context.Context, userInfo *model.ContextUser, entityData interface{}) (where g.Map, err error)
HasAccessByDataWhere(ctx context.Context, where g.Map,uid interface{}) bool
}
)