mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-04 04:54:32 +08:00
39 lines
973 B
Go
39 lines
973 B
Go
package userutils
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/iwind/TeaGo/maps"
|
|
)
|
|
|
|
var ErrUserNotFound = errors.New("not found user")
|
|
|
|
// InitUser 查找用户基本信息
|
|
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 ErrUserNotFound
|
|
}
|
|
|
|
// AccessKey数量
|
|
countAccessKeysResp, err := p.RPC().UserAccessKeyRPC().CountAllEnabledUserAccessKeys(p.AdminContext(), &pb.CountAllEnabledUserAccessKeysRequest{
|
|
AdminId: 0,
|
|
UserId: userId,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
p.Data["user"] = maps.Map{
|
|
"id": userId,
|
|
"fullname": resp.User.Fullname,
|
|
"username": resp.User.Username,
|
|
"countAccessKeys": countAccessKeysResp.Count,
|
|
}
|
|
return nil
|
|
}
|