package rbac import ( "context" "cp-organization-management/errors" "cp-organization-management/model" pb_v1 "cp-organization-management/pb/v1" "cp-organization-management/utils" "encoding/json" "fmt" "github.com/jaryhe/gopkgs/database" "github.com/jaryhe/gopkgs/logger" "github.com/jinzhu/gorm" "go.uber.org/zap" "google.golang.org/grpc/status" ) func RbacGroupList(ctx context.Context, req *pb_v1.RbacGroupListRequest) (reply *pb_v1.RbacGroupListReply, err error) { reply = &pb_v1.RbacGroupListReply{} // 捕获各个task中的异常并返回给调用者 defer func() { if r := recover(); r != nil { err = fmt.Errorf("%+v", r) e := &status.Status{} if er := json.Unmarshal([]byte(err.Error()), e); er != nil { logger.Error("err", zap.String("system_err", err.Error()), zap.Stack("stacktrace")) } } }() if req.OrganizationCode == "" { return nil, errors.ParamsError } dbname := utils.GetDbName(req.OrganizationCode) p := model.NewRbacGroup(dbname) list := []model.RbacGroup{} where := map[string]interface{}{ "is_super_group":false, } // 超级管理员可以看见所有 if req.IsSuper { where = nil } err = p.QueryAll(database.DB(), where, &list) if err != nil { if err == gorm.ErrRecordNotFound { return reply, nil } return nil, errors.DataBaseError } reply.List = make([]*pb_v1.RbacGroupItem, len(list)) for i, v := range list { reply.List[i] = &pb_v1.RbacGroupItem{ Name: v.Name, Id: v.Id, } } return reply, nil }