|
|
@ -16,7 +16,7 @@ package user
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"errors"
|
|
|
|
"math/rand"
|
|
|
|
"math/rand"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
@ -61,17 +61,17 @@ func (s *userServer) GetGroupOnlineUser(ctx context.Context, req *pbuser.GetGrou
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Start(config *config.GlobalConfig, client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
|
|
|
func Start(config *config.GlobalConfig, client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
|
|
|
rdb, err := cache.NewRedis(config)
|
|
|
|
rdb, err := cache.NewRedis(&config.Redis)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mongo, err := unrelation.NewMongo(config)
|
|
|
|
mongo, err := unrelation.NewMongo(&config.Mongo)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
users := make([]*tablerelation.UserModel, 0)
|
|
|
|
users := make([]*tablerelation.UserModel, 0)
|
|
|
|
if len(config.IMAdmin.UserID) != len(config.IMAdmin.Nickname) {
|
|
|
|
if len(config.IMAdmin.UserID) != len(config.IMAdmin.Nickname) {
|
|
|
|
return errs.Wrap(fmt.Errorf("the count of ImAdmin.UserID is not equal to the count of ImAdmin.Nickname"))
|
|
|
|
return errs.Wrap(errors.New("the count of ImAdmin.UserID is not equal to the count of ImAdmin.Nickname"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for k, v := range config.IMAdmin.UserID {
|
|
|
|
for k, v := range config.IMAdmin.UserID {
|
|
|
|
users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.IMAdmin.Nickname[k], AppMangerLevel: constant.AppNotificationAdmin})
|
|
|
|
users = append(users, &tablerelation.UserModel{UserID: v, Nickname: config.IMAdmin.Nickname[k], AppMangerLevel: constant.AppNotificationAdmin})
|
|
|
@ -83,15 +83,15 @@ func Start(config *config.GlobalConfig, client registry.SvcDiscoveryRegistry, se
|
|
|
|
cache := cache.NewUserCacheRedis(rdb, userDB, cache.GetDefaultOpt())
|
|
|
|
cache := cache.NewUserCacheRedis(rdb, userDB, cache.GetDefaultOpt())
|
|
|
|
userMongoDB := unrelation.NewUserMongoDriver(mongo.GetDatabase(config.Mongo.Database))
|
|
|
|
userMongoDB := unrelation.NewUserMongoDriver(mongo.GetDatabase(config.Mongo.Database))
|
|
|
|
database := controller.NewUserDatabase(userDB, cache, tx.NewMongo(mongo.GetClient()), userMongoDB)
|
|
|
|
database := controller.NewUserDatabase(userDB, cache, tx.NewMongo(mongo.GetClient()), userMongoDB)
|
|
|
|
friendRpcClient := rpcclient.NewFriendRpcClient(client, config)
|
|
|
|
friendRpcClient := rpcclient.NewFriendRpcClient(client, config.RpcRegisterName.OpenImFriendName)
|
|
|
|
groupRpcClient := rpcclient.NewGroupRpcClient(client, config)
|
|
|
|
groupRpcClient := rpcclient.NewGroupRpcClient(client, config.RpcRegisterName.OpenImGroupName)
|
|
|
|
msgRpcClient := rpcclient.NewMessageRpcClient(client, config)
|
|
|
|
msgRpcClient := rpcclient.NewMessageRpcClient(client, config.RpcRegisterName.OpenImMsgName)
|
|
|
|
u := &userServer{
|
|
|
|
u := &userServer{
|
|
|
|
UserDatabase: database,
|
|
|
|
UserDatabase: database,
|
|
|
|
RegisterCenter: client,
|
|
|
|
RegisterCenter: client,
|
|
|
|
friendRpcClient: &friendRpcClient,
|
|
|
|
friendRpcClient: &friendRpcClient,
|
|
|
|
groupRpcClient: &groupRpcClient,
|
|
|
|
groupRpcClient: &groupRpcClient,
|
|
|
|
friendNotificationSender: notification.NewFriendNotificationSender(config, &msgRpcClient, notification.WithDBFunc(database.FindWithError)),
|
|
|
|
friendNotificationSender: notification.NewFriendNotificationSender(&config.Notification, &msgRpcClient, notification.WithDBFunc(database.FindWithError)),
|
|
|
|
userNotificationSender: notification.NewUserNotificationSender(config, &msgRpcClient, notification.WithUserFunc(database.FindWithError)),
|
|
|
|
userNotificationSender: notification.NewUserNotificationSender(config, &msgRpcClient, notification.WithUserFunc(database.FindWithError)),
|
|
|
|
config: config,
|
|
|
|
config: config,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -111,7 +111,7 @@ func (s *userServer) GetDesignateUsers(ctx context.Context, req *pbuser.GetDesig
|
|
|
|
|
|
|
|
|
|
|
|
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserInfoReq) (resp *pbuser.UpdateUserInfoResp, err error) {
|
|
|
|
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserInfoReq) (resp *pbuser.UpdateUserInfoResp, err error) {
|
|
|
|
resp = &pbuser.UpdateUserInfoResp{}
|
|
|
|
resp = &pbuser.UpdateUserInfoResp{}
|
|
|
|
err = authverify.CheckAccessV3(ctx, req.UserInfo.UserID, s.config)
|
|
|
|
err = authverify.CheckAccessV3(ctx, req.UserInfo.UserID, &s.config.Manager, &s.config.IMAdmin)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -145,7 +145,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (s *userServer) UpdateUserInfoEx(ctx context.Context, req *pbuser.UpdateUserInfoExReq) (resp *pbuser.UpdateUserInfoExResp, err error) {
|
|
|
|
func (s *userServer) UpdateUserInfoEx(ctx context.Context, req *pbuser.UpdateUserInfoExReq) (resp *pbuser.UpdateUserInfoExResp, err error) {
|
|
|
|
resp = &pbuser.UpdateUserInfoExResp{}
|
|
|
|
resp = &pbuser.UpdateUserInfoExResp{}
|
|
|
|
err = authverify.CheckAccessV3(ctx, req.UserInfo.UserID, s.config)
|
|
|
|
err = authverify.CheckAccessV3(ctx, req.UserInfo.UserID, &s.config.Manager, &s.config.IMAdmin)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -197,7 +197,7 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckR
|
|
|
|
if utils.Duplicate(req.CheckUserIDs) {
|
|
|
|
if utils.Duplicate(req.CheckUserIDs) {
|
|
|
|
return nil, errs.ErrArgs.WrapMsg("userID repeated")
|
|
|
|
return nil, errs.ErrArgs.WrapMsg("userID repeated")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = authverify.CheckAdmin(ctx, s.config)
|
|
|
|
err = authverify.CheckAdmin(ctx, &s.config.Manager, &s.config.IMAdmin)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -383,7 +383,7 @@ func (s *userServer) GetSubscribeUsersStatus(ctx context.Context,
|
|
|
|
|
|
|
|
|
|
|
|
// ProcessUserCommandAdd user general function add.
|
|
|
|
// ProcessUserCommandAdd user general function add.
|
|
|
|
func (s *userServer) ProcessUserCommandAdd(ctx context.Context, req *pbuser.ProcessUserCommandAddReq) (*pbuser.ProcessUserCommandAddResp, error) {
|
|
|
|
func (s *userServer) ProcessUserCommandAdd(ctx context.Context, req *pbuser.ProcessUserCommandAddReq) (*pbuser.ProcessUserCommandAddResp, error) {
|
|
|
|
err := authverify.CheckAccessV3(ctx, req.UserID, s.config)
|
|
|
|
err := authverify.CheckAccessV3(ctx, req.UserID, &s.config.Manager, &s.config.IMAdmin)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -414,7 +414,7 @@ func (s *userServer) ProcessUserCommandAdd(ctx context.Context, req *pbuser.Proc
|
|
|
|
|
|
|
|
|
|
|
|
// ProcessUserCommandDelete user general function delete.
|
|
|
|
// ProcessUserCommandDelete user general function delete.
|
|
|
|
func (s *userServer) ProcessUserCommandDelete(ctx context.Context, req *pbuser.ProcessUserCommandDeleteReq) (*pbuser.ProcessUserCommandDeleteResp, error) {
|
|
|
|
func (s *userServer) ProcessUserCommandDelete(ctx context.Context, req *pbuser.ProcessUserCommandDeleteReq) (*pbuser.ProcessUserCommandDeleteResp, error) {
|
|
|
|
err := authverify.CheckAccessV3(ctx, req.UserID, s.config)
|
|
|
|
err := authverify.CheckAccessV3(ctx, req.UserID, &s.config.Manager, &s.config.IMAdmin)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -437,7 +437,7 @@ func (s *userServer) ProcessUserCommandDelete(ctx context.Context, req *pbuser.P
|
|
|
|
|
|
|
|
|
|
|
|
// ProcessUserCommandUpdate user general function update.
|
|
|
|
// ProcessUserCommandUpdate user general function update.
|
|
|
|
func (s *userServer) ProcessUserCommandUpdate(ctx context.Context, req *pbuser.ProcessUserCommandUpdateReq) (*pbuser.ProcessUserCommandUpdateResp, error) {
|
|
|
|
func (s *userServer) ProcessUserCommandUpdate(ctx context.Context, req *pbuser.ProcessUserCommandUpdateReq) (*pbuser.ProcessUserCommandUpdateResp, error) {
|
|
|
|
err := authverify.CheckAccessV3(ctx, req.UserID, s.config)
|
|
|
|
err := authverify.CheckAccessV3(ctx, req.UserID, &s.config.Manager, &s.config.IMAdmin)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -469,7 +469,7 @@ func (s *userServer) ProcessUserCommandUpdate(ctx context.Context, req *pbuser.P
|
|
|
|
|
|
|
|
|
|
|
|
func (s *userServer) ProcessUserCommandGet(ctx context.Context, req *pbuser.ProcessUserCommandGetReq) (*pbuser.ProcessUserCommandGetResp, error) {
|
|
|
|
func (s *userServer) ProcessUserCommandGet(ctx context.Context, req *pbuser.ProcessUserCommandGetReq) (*pbuser.ProcessUserCommandGetResp, error) {
|
|
|
|
|
|
|
|
|
|
|
|
err := authverify.CheckAccessV3(ctx, req.UserID, s.config)
|
|
|
|
err := authverify.CheckAccessV3(ctx, req.UserID, &s.config.Manager, &s.config.IMAdmin)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -498,7 +498,7 @@ func (s *userServer) ProcessUserCommandGet(ctx context.Context, req *pbuser.Proc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *userServer) ProcessUserCommandGetAll(ctx context.Context, req *pbuser.ProcessUserCommandGetAllReq) (*pbuser.ProcessUserCommandGetAllResp, error) {
|
|
|
|
func (s *userServer) ProcessUserCommandGetAll(ctx context.Context, req *pbuser.ProcessUserCommandGetAllReq) (*pbuser.ProcessUserCommandGetAllResp, error) {
|
|
|
|
err := authverify.CheckAccessV3(ctx, req.UserID, s.config)
|
|
|
|
err := authverify.CheckAccessV3(ctx, req.UserID, &s.config.Manager, &s.config.IMAdmin)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|