mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-25 23:59:58 +08:00
Merge pull request #1666 from luhaoling/releases
fix: fix the imAdmin permission and searchNoficitaion resp
This commit is contained in:
commit
019ef60616
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.19
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
firebase.google.com/go v3.13.0+incompatible
|
firebase.google.com/go v3.13.0+incompatible
|
||||||
github.com/OpenIMSDK/protocol v0.0.42
|
github.com/OpenIMSDK/protocol v0.0.43
|
||||||
github.com/OpenIMSDK/tools v0.0.21
|
github.com/OpenIMSDK/tools v0.0.21
|
||||||
github.com/bwmarrin/snowflake v0.3.0 // indirect
|
github.com/bwmarrin/snowflake v0.3.0 // indirect
|
||||||
github.com/dtm-labs/rockscache v0.1.1
|
github.com/dtm-labs/rockscache v0.1.1
|
||||||
|
@ -515,7 +515,7 @@ func (s *userServer) SearchNotificationAccount(ctx context.Context, req *pbuser.
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
_, users, err := s.UserDatabase.Page(ctx, req.Pagination)
|
users, err := s.UserDatabase.FindNotification(ctx, constant.AppNotificationAdmin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -558,7 +558,7 @@ func (s *userServer) userModelToResp(users []*relation.UserModel) *pbuser.Search
|
|||||||
accounts := make([]*pbuser.NotificationAccountInfo, 0)
|
accounts := make([]*pbuser.NotificationAccountInfo, 0)
|
||||||
var total int64
|
var total int64
|
||||||
for _, v := range users {
|
for _, v := range users {
|
||||||
if v.AppMangerLevel == constant.AppNotificationAdmin || v.AppMangerLevel == constant.AppAdmin {
|
if v.AppMangerLevel == constant.AppNotificationAdmin && !utils.IsContain(v.UserID, config.Config.IMAdmin.UserID) {
|
||||||
temp := &pbuser.NotificationAccountInfo{
|
temp := &pbuser.NotificationAccountInfo{
|
||||||
UserID: v.UserID,
|
UserID: v.UserID,
|
||||||
FaceURL: v.FaceURL,
|
FaceURL: v.FaceURL,
|
||||||
|
@ -38,6 +38,9 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
|
|||||||
if utils.IsContain(opUserID, config.Config.Manager.UserID) {
|
if utils.IsContain(opUserID, config.Config.Manager.UserID) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if utils.IsContain(opUserID, config.Config.IMAdmin.UserID) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if opUserID == ownerUserID {
|
if opUserID == ownerUserID {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -45,13 +48,16 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsAppManagerUid(ctx context.Context) bool {
|
func IsAppManagerUid(ctx context.Context) bool {
|
||||||
return utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID)
|
return utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) || utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.IMAdmin.UserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckAdmin(ctx context.Context) error {
|
func CheckAdmin(ctx context.Context) error {
|
||||||
if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) {
|
if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.IMAdmin.UserID) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return errs.ErrNoPermission.Wrap(fmt.Sprintf("user %s is not admin userID", mcontext.GetOpUserID(ctx)))
|
return errs.ErrNoPermission.Wrap(fmt.Sprintf("user %s is not admin userID", mcontext.GetOpUserID(ctx)))
|
||||||
}
|
}
|
||||||
func CheckIMAdmin(ctx context.Context) error {
|
func CheckIMAdmin(ctx context.Context) error {
|
||||||
@ -69,7 +75,7 @@ func ParseRedisInterfaceToken(redisToken any) (*tokenverify.Claims, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsManagerUserID(opUserID string) bool {
|
func IsManagerUserID(opUserID string) bool {
|
||||||
return utils.IsContain(opUserID, config.Config.Manager.UserID)
|
return utils.IsContain(opUserID, config.Config.Manager.UserID) || utils.IsContain(opUserID, config.Config.IMAdmin.UserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WsVerifyToken(token, userID string, platformID int) error {
|
func WsVerifyToken(token, userID string, platformID int) error {
|
||||||
|
@ -40,6 +40,8 @@ type UserDatabase interface {
|
|||||||
Find(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error)
|
Find(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error)
|
||||||
// Find userInfo By Nickname
|
// Find userInfo By Nickname
|
||||||
FindByNickname(ctx context.Context, nickname string) (users []*relation.UserModel, err error)
|
FindByNickname(ctx context.Context, nickname string) (users []*relation.UserModel, err error)
|
||||||
|
// Find notificationAccounts
|
||||||
|
FindNotification(ctx context.Context, level int64) (users []*relation.UserModel, err error)
|
||||||
// Create Insert multiple external guarantees that the userID is not repeated and does not exist in the db
|
// Create Insert multiple external guarantees that the userID is not repeated and does not exist in the db
|
||||||
Create(ctx context.Context, users []*relation.UserModel) (err error)
|
Create(ctx context.Context, users []*relation.UserModel) (err error)
|
||||||
// Update update (non-zero value) external guarantee userID exists
|
// Update update (non-zero value) external guarantee userID exists
|
||||||
@ -140,6 +142,11 @@ func (u *userDatabase) FindByNickname(ctx context.Context, nickname string) (use
|
|||||||
return u.userDB.TakeByNickname(ctx, nickname)
|
return u.userDB.TakeByNickname(ctx, nickname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find notificationAccouts
|
||||||
|
func (u *userDatabase) FindNotification(ctx context.Context, level int64) (users []*relation.UserModel, err error) {
|
||||||
|
return u.userDB.TakeNotification(ctx, level)
|
||||||
|
}
|
||||||
|
|
||||||
// Create Insert multiple external guarantees that the userID is not repeated and does not exist in the db.
|
// Create Insert multiple external guarantees that the userID is not repeated and does not exist in the db.
|
||||||
func (u *userDatabase) Create(ctx context.Context, users []*relation.UserModel) (err error) {
|
func (u *userDatabase) Create(ctx context.Context, users []*relation.UserModel) (err error) {
|
||||||
return u.tx.Transaction(ctx, func(ctx context.Context) error {
|
return u.tx.Transaction(ctx, func(ctx context.Context) error {
|
||||||
|
@ -65,6 +65,10 @@ func (u *UserMgo) Take(ctx context.Context, userID string) (user *relation.UserM
|
|||||||
return mgoutil.FindOne[*relation.UserModel](ctx, u.coll, bson.M{"user_id": userID})
|
return mgoutil.FindOne[*relation.UserModel](ctx, u.coll, bson.M{"user_id": userID})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *UserMgo) TakeNotification(ctx context.Context, level int64) (user []*relation.UserModel, err error) {
|
||||||
|
return mgoutil.Find[*relation.UserModel](ctx, u.coll, bson.M{"app_manger_level": level})
|
||||||
|
}
|
||||||
|
|
||||||
func (u *UserMgo) TakeByNickname(ctx context.Context, nickname string) (user []*relation.UserModel, err error) {
|
func (u *UserMgo) TakeByNickname(ctx context.Context, nickname string) (user []*relation.UserModel, err error) {
|
||||||
return mgoutil.Find[*relation.UserModel](ctx, u.coll, bson.M{"nickname": nickname})
|
return mgoutil.Find[*relation.UserModel](ctx, u.coll, bson.M{"nickname": nickname})
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ type UserModelInterface interface {
|
|||||||
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
||||||
Find(ctx context.Context, userIDs []string) (users []*UserModel, err error)
|
Find(ctx context.Context, userIDs []string) (users []*UserModel, err error)
|
||||||
Take(ctx context.Context, userID string) (user *UserModel, err error)
|
Take(ctx context.Context, userID string) (user *UserModel, err error)
|
||||||
|
TakeNotification(ctx context.Context, level int64) (user []*UserModel, err error)
|
||||||
TakeByNickname(ctx context.Context, nickname string) (user []*UserModel, err error)
|
TakeByNickname(ctx context.Context, nickname string) (user []*UserModel, err error)
|
||||||
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
||||||
Exist(ctx context.Context, userID string) (exist bool, err error)
|
Exist(ctx context.Context, userID string) (exist bool, err error)
|
||||||
|
@ -64,6 +64,9 @@ func NewUserRpcClient(client discoveryregistry.SvcDiscoveryRegistry) UserRpcClie
|
|||||||
|
|
||||||
// GetUsersInfo retrieves information for multiple users based on their user IDs.
|
// GetUsersInfo retrieves information for multiple users based on their user IDs.
|
||||||
func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
|
func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
|
||||||
|
if len(userIDs) == 0 {
|
||||||
|
return []*sdkws.UserInfo{}, nil
|
||||||
|
}
|
||||||
resp, err := u.Client.GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
|
resp, err := u.Client.GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
|
||||||
UserIDs: userIDs,
|
UserIDs: userIDs,
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user