2020-12-04 16:00:55 +08:00
|
|
|
package userutils
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
|
|
|
|
)
|
|
|
|
|
|
2021-06-20 19:23:02 +08:00
|
|
|
// InitUser 查找用户基本信息
|
2020-12-04 16:00:55 +08:00
|
|
|
func InitUser(p *actionutils.ParentAction, userId int64) error {
|
|
|
|
|
resp, err := p.RPC().UserRPC().FindEnabledUser(p.AdminContext(), &pb.FindEnabledUserRequest{UserId: userId})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if resp.User == nil {
|
|
|
|
|
return errors.New("not found user")
|
|
|
|
|
}
|
2021-06-20 19:23:02 +08:00
|
|
|
|
|
|
|
|
// AccessKey数量
|
|
|
|
|
countAccessKeysResp, err := p.RPC().UserAccessKeyRPC().CountAllEnabledUserAccessKeys(p.AdminContext(), &pb.CountAllEnabledUserAccessKeysRequest{
|
|
|
|
|
AdminId: 0,
|
|
|
|
|
UserId: userId,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 16:00:55 +08:00
|
|
|
p.Data["user"] = maps.Map{
|
2021-06-20 19:23:02 +08:00
|
|
|
"id": userId,
|
|
|
|
|
"fullname": resp.User.Fullname,
|
|
|
|
|
"username": resp.User.Username,
|
|
|
|
|
"countAccessKeys": countAccessKeysResp.Count,
|
2020-12-04 16:00:55 +08:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|