mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-27 20:30:40 +08:00
1
This commit is contained in:
parent
142b9386fc
commit
8e47b55ab4
@ -4,7 +4,6 @@ import (
|
|||||||
chat "Open_IM/internal/rpc/msg"
|
chat "Open_IM/internal/rpc/msg"
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
rocksCache "Open_IM/pkg/common/db/cache"
|
|
||||||
"Open_IM/pkg/common/db/model"
|
"Open_IM/pkg/common/db/model"
|
||||||
"Open_IM/pkg/common/db/mysql"
|
"Open_IM/pkg/common/db/mysql"
|
||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
@ -173,8 +172,8 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
|||||||
|
|
||||||
func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.ImportFriendResp, error) {
|
func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.ImportFriendResp, error) {
|
||||||
resp := &pbFriend.ImportFriendResp{}
|
resp := &pbFriend.ImportFriendResp{}
|
||||||
if !utils.IsContain(tools.OpUserID(ctx), config.Config.Manager.AppManagerUid) {
|
if err := token_verify.CheckAdmin(ctx); err != nil {
|
||||||
return nil, constant.ErrNoPermission.Wrap()
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := GetUserInfo(ctx, req.FromUserID); err != nil {
|
if _, err := GetUserInfo(ctx, req.FromUserID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -315,11 +314,11 @@ func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlac
|
|||||||
if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil {
|
if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
blackIDList, err := rocksCache.GetBlackListFromCache(ctx, req.FromUserID)
|
exist, err := s.blackModel.IsExist(ctx, req.FromUserID, req.ToUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp.Response = utils.IsContain(req.ToUserID, blackIDList)
|
resp.Response = exist
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"Open_IM/pkg/common/db/cache"
|
"Open_IM/pkg/common/db/cache"
|
||||||
"Open_IM/pkg/common/db/mysql"
|
"Open_IM/pkg/common/db/mysql"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BlackModel struct {
|
type BlackModel struct {
|
||||||
@ -31,10 +33,20 @@ func (b *BlackModel) Find(ctx context.Context, blacks []*mysql.Black) (blackList
|
|||||||
return b.db.Find(ctx, blacks)
|
return b.db.Find(ctx, blacks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlackModel) Take(ctx context.Context, blackID string) (black *mysql.Black, err error) {
|
func (b *BlackModel) Take(ctx context.Context, ownerUserID, blockUserID string) (black *mysql.Black, err error) {
|
||||||
return b.db.Take(ctx, blackID)
|
return b.db.Take(ctx, ownerUserID, blockUserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlackModel) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*mysql.Black, err error) {
|
func (b *BlackModel) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*mysql.Black, err error) {
|
||||||
return b.db.FindByOwnerUserID(ctx, ownerUserID)
|
return b.db.FindByOwnerUserID(ctx, ownerUserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BlackModel) IsExist(ctx context.Context, ownerUserID, blockUserID string) (bool, error) {
|
||||||
|
if _, err := b.Take(ctx, ownerUserID, blockUserID); err == nil {
|
||||||
|
return true, nil
|
||||||
|
} else if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return false, nil
|
||||||
|
} else {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -63,12 +63,12 @@ func (b *Black) Find(ctx context.Context, blacks []*Black) (blackList []*Black,
|
|||||||
return blackList, utils.Wrap(GroupMemberDB.Where("(owner_user_id, block_user_id) in ?", where).Find(&blackList).Error, "")
|
return blackList, utils.Wrap(GroupMemberDB.Where("(owner_user_id, block_user_id) in ?", where).Find(&blackList).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Black) Take(ctx context.Context, blackID string) (black *Black, err error) {
|
func (b *Black) Take(ctx context.Context, ownerUserID, blockUserID string) (black *Black, err error) {
|
||||||
black = &Black{}
|
black = &Black{}
|
||||||
defer func() {
|
defer func() {
|
||||||
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "blackID", blackID, "black", *black)
|
trace_log.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "blockUserID", blockUserID, "black", *black)
|
||||||
}()
|
}()
|
||||||
return black, utils.Wrap(b.DB.Where("black_id = ?", blackID).Take(black).Error, "")
|
return black, utils.Wrap(b.DB.Where("owner_user_id = ? and block_user_id = ?", ownerUserID, blockUserID).Take(black).Error, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Black) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*Black, err error) {
|
func (b *Black) FindByOwnerUserID(ctx context.Context, ownerUserID string) (blackList []*Black, err error) {
|
||||||
|
@ -173,6 +173,13 @@ func CheckAccessV3(ctx context.Context, OwnerUserID string) (err error) {
|
|||||||
return constant.ErrIdentity.Wrap(utils.GetSelfFuncName())
|
return constant.ErrIdentity.Wrap(utils.GetSelfFuncName())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckAdmin(ctx context.Context) error {
|
||||||
|
if utils.IsContain(tools.OpUserID(ctx), config.Config.Manager.AppManagerUid) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return constant.ErrIdentity.Wrap()
|
||||||
|
}
|
||||||
|
|
||||||
func GetUserIDFromToken(token string, operationID string) (bool, string, string) {
|
func GetUserIDFromToken(token string, operationID string) (bool, string, string) {
|
||||||
claims, err := ParseToken(token, operationID)
|
claims, err := ParseToken(token, operationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user