12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package rbac
- import (
- "gd_admin/apis"
- "gd_admin/errors"
- "gd_admin/impl/dbmodel"
- "encoding/json"
- "fmt"
- "gd_admin/common.in/jsonrpc2"
- "gd_admin/common.in/utils"
- "github.com/astaxie/beego/orm"
- "go.uber.org/zap"
- "golang.org/x/net/context"
- )
- // 获取用户权限节点列表
- func getUserRbacNode(id int) (string, error) {
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err := fmt.Errorf("%+v", r)
- e := &jsonrpc2.Error{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- l.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- // where
- filter := map[string]interface{}{
- "id": id,
- }
- p := dbmodel.TGdAdminRbacGroup{}
- err := p.Fetch(orm.NewOrm(), filter)
- if err != nil {
- if err == orm.ErrNoRows {
- return "", errors.AccessNotAllow
- }
- l.Error("mysql",
- zap.String("sql", fmt.Sprintf("SELECT * FROM %s", p.TableName())),
- zap.String("fields", utils.MarshalJsonString(filter)),
- zap.String("error", err.Error()))
- return "", errors.DataBaseError
- }
- return p.RbacNodeList, nil
- }
- // 获取所有的节点列表
- func GetList(ctx context.Context, req *apis.GetNodeListReq, reply *apis.GetNodeListReply) error {
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err := fmt.Errorf("%+v", r)
- e := &jsonrpc2.Error{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- l.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- // where
- filter := map[string]interface{}{}
- p := dbmodel.TGdAdminRbacNode{}
- list, err := p.FetchAll(orm.NewOrm(), filter, []string{"id", "name", "pid"})
- if err != nil {
- l.Error("mysql",
- zap.String("sql", fmt.Sprintf("SELECT * FROM %s", p.TableName())),
- zap.String("fields", utils.MarshalJsonString(filter)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- for k := range list {
- reply.List = append(reply.List, apis.RbacNodeList{
- Id: list[k].Id,
- Name: list[k].Name,
- Pid: list[k].Pid,
- })
- }
- return nil
- }
|