fix version 1
This commit is contained in:
@@ -23,6 +23,14 @@ func ApplyDoMessage(ctx context.Context, in *pb.ApplyMessageRequest) (reply *pb.
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 校验该申请存在且属于当前调用者(申请方或被申请方),避免污染他人申请会话
|
||||
var apply models.FriendApply
|
||||
err = impl.DBService.Where("id=? and (from_identity=? or to_identity=?)", in.ApplyId, auth.Identity, auth.Identity).First(&apply).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
msg := models.FriendApplyMessage{
|
||||
ApplyID: uint(in.ApplyId),
|
||||
Body: in.Body,
|
||||
@@ -36,8 +44,8 @@ func ApplyDoMessage(ctx context.Context, in *pb.ApplyMessageRequest) (reply *pb.
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
//回写最后一次交流的消息ID
|
||||
err = impl.DBService.Model(models.FriendApply{}).Where("id=?", msg.ApplyID).UpdateColumn("last_message_id", msg.ID).Error
|
||||
//回写最后一次交流的消息ID(仍限定申请归属)
|
||||
err = impl.DBService.Model(models.FriendApply{}).Where("id=? and (from_identity=? or to_identity=?)", msg.ApplyID, auth.Identity, auth.Identity).UpdateColumn("last_message_id", msg.ID).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
@@ -25,12 +25,24 @@ func ApplyDoPass(ctx context.Context, in *pb.ApplyDoPassRequest) (reply *pb.Data
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 通过前先按 identity 查出属于当前调用者(被申请方)的申请记录
|
||||
var apply models.FriendApply
|
||||
err = impl.DBService.Where("identity=? and to_identity=?", in.ApplyIdentity, auth.Identity).First(&apply).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
// 申请记录里的申请人必须与请求要加为好友的对象一致,否则视为无申请依据
|
||||
if apply.FromIdentity != in.FriendRelationIdentity {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
//写入好友表
|
||||
friend := &models.RelationFriend{FriendrelationID: uint(in.FriendRelationId), FriendrelationIdentity: in.FriendRelationIdentity}
|
||||
friend := &models.RelationFriend{FriendrelationID: apply.FromID, FriendrelationIdentity: apply.FromIdentity}
|
||||
friend.Identity = utils.UUID()
|
||||
friend.PassportID = auth.ID
|
||||
friend.PassportIdentity = auth.Identity
|
||||
friend.SessionID = common.UniqueSessionID(auth.Identity, in.FriendRelationIdentity)
|
||||
friend.SessionID = common.UniqueSessionID(auth.Identity, apply.FromIdentity)
|
||||
|
||||
err = impl.DBService.Create(&friend).Error
|
||||
if err != nil {
|
||||
@@ -40,7 +52,7 @@ func ApplyDoPass(ctx context.Context, in *pb.ApplyDoPassRequest) (reply *pb.Data
|
||||
|
||||
//EventMQ:向mesh MQ中心发送报文,请求推送消息以及更新Cache.
|
||||
|
||||
err = impl.DBService.Model(models.FriendApply{}).Where("to_identity=? and identity=?", auth.Identity, in.ApplyIdentity).UpdateColumn("status", 1).Error
|
||||
err = impl.DBService.Model(models.FriendApply{}).Where("to_identity=? and identity=?", auth.Identity, apply.Identity).UpdateColumn("status", 1).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
@@ -45,8 +45,12 @@ func ApplyFetch(ctx context.Context, in *pb.VersionRequest) (reply *pb.ApplyFetc
|
||||
}
|
||||
|
||||
if cacheErr != nil {
|
||||
printer.Error(err.Error())
|
||||
printer.Error(cacheErr.Error())
|
||||
return nil, errcode.ErrRedis
|
||||
}
|
||||
if reply == nil {
|
||||
// 版本一致未走查询分支时兜底返回非 nil 空集合,避免序列化失败
|
||||
reply = &pb.ApplyFetchReply{}
|
||||
}
|
||||
return reply, nil
|
||||
}
|
||||
|
||||
@@ -10,11 +10,12 @@ import (
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 好友申请详情
|
||||
func ApplyGet(ctx context.Context, in *pb.IdentRequest) (reply *pb.FriendApplyGetReply, err error) {
|
||||
_, err = service.ParseMetaCtx(ctx, nil)
|
||||
auth, err := service.ParseMetaCtx(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -22,10 +23,14 @@ func ApplyGet(ctx context.Context, in *pb.IdentRequest) (reply *pb.FriendApplyGe
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// 只允许查看与自己相关的申请(申请方或被申请方)
|
||||
var apply models.FriendApply
|
||||
err = impl.DBService.Where("identity=?", in.Identity).First(&apply).Error
|
||||
err = impl.DBService.Where("identity=? and (from_identity=? or to_identity=?)", in.Identity, auth.Identity, auth.Identity).First(&apply).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@ func Delete(ctx context.Context, in *pb.IdentRequest) (reply *pb.DataStatusReply
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Delete("relation_id=? and identity=?", auth.ID, in.Identity).Error
|
||||
// 归属列是 passport_id,in.Identity 是好友身份(friend_relation_identity)
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Delete("passport_id=? and friend_relation_identity=?", auth.ID, in.Identity).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
@@ -24,7 +24,8 @@ func DoPopular(ctx context.Context, in *pb.IdentRequest) (reply *pb.DataStatusRe
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("relation_id=? and identity=?", auth.ID, in.Identity).UpdateColumn("popular", 1).Error
|
||||
// 归属列是 passport_id,in.Identity 是好友身份(friend_relation_identity)
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("passport_id=? and friend_relation_identity=?", auth.ID, in.Identity).UpdateColumn("popular", 1).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
@@ -45,8 +45,12 @@ func Fetch(ctx context.Context, in *pb.VersionRequest) (reply *pb.FriendsReply,
|
||||
}
|
||||
|
||||
if cacheErr != nil {
|
||||
printer.Error(err.Error())
|
||||
printer.Error(cacheErr.Error())
|
||||
return nil, errcode.ErrRedis
|
||||
}
|
||||
if reply == nil {
|
||||
// 版本一致未走查询分支时兜底返回非 nil 空集合,避免序列化失败
|
||||
reply = &pb.FriendsReply{}
|
||||
}
|
||||
return reply, nil
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ func ModifyNickname(ctx context.Context, in *pb.ModifyNicknameRequest) (reply *p
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("relation_id=? and identity=?", auth.ID, in.Identity).UpdateColumn("nickname", in.Nickname).Error
|
||||
// 归属列是 passport_id,in.Identity 是好友身份(friend_relation_identity);备注列是 remark_name
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("passport_id=? and friend_relation_identity=?", auth.ID, in.Identity).UpdateColumn("remark_name", in.Nickname).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
@@ -27,6 +27,24 @@ func TagDoUpdate(ctx context.Context, in *pb.TagDoUpdateRequest) (reply *pb.Data
|
||||
|
||||
switch strings.ToUpper(in.Direction) {
|
||||
case "ADD":
|
||||
// 校验标签归属当前调用者
|
||||
var tag models.FriendTag
|
||||
err = impl.DBService.Where("identity=? and passport_id=?", in.TagIdentity, auth.ID).First(&tag).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
// 校验目标确实是当前调用者的好友
|
||||
var friendCount int64
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("passport_id=? and friend_relation_identity=?", auth.ID, in.FriendIdentity).Count(&friendCount).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
if friendCount == 0 {
|
||||
return nil, errcode.ErrPermissionDenied
|
||||
}
|
||||
|
||||
data := models.FriendInTag{
|
||||
FriendIdentity: in.FriendIdentity,
|
||||
TagIdentity: in.TagIdentity,
|
||||
@@ -36,7 +54,8 @@ func TagDoUpdate(ctx context.Context, in *pb.TagDoUpdateRequest) (reply *pb.Data
|
||||
|
||||
err = impl.DBService.Create(&data).Error
|
||||
case "DEL":
|
||||
err = impl.DBService.Model(models.FriendInTag{}).Delete("friend_identity=? and tag_identity=?", in.FriendIdentity, in.TagIdentity).Error
|
||||
// 归属列是 passport_id,只能移除自己标签内的成员
|
||||
err = impl.DBService.Model(models.FriendInTag{}).Delete("friend_identity=? and tag_identity=? and passport_id=?", in.FriendIdentity, in.TagIdentity, auth.ID).Error
|
||||
default:
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
@@ -19,7 +19,15 @@ func TagFetch(ctx context.Context, in *pb.Empty) (reply *pb.FriendTagsReply, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.FriendTag{}).Where("relation_id=?", auth.ID).Count(&reply.Total).Order("id asc").Scan(&reply.Data).Error
|
||||
// 先初始化返回值,避免对 nil 指针取字段地址
|
||||
reply = &pb.FriendTagsReply{}
|
||||
// 标签归属列是 passport_id
|
||||
err = impl.DBService.Model(models.FriendTag{}).Where("passport_id=?", auth.ID).Count(&reply.Total).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
err = impl.DBService.Model(models.FriendTag{}).Select("id, identity, name as tag_name").Where("passport_id=?", auth.ID).Order("id asc").Scan(&reply.Data).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
@@ -23,8 +23,9 @@ func TagMemberFetch(ctx context.Context, in *pb.IdentRequest) (reply *pb.PartFri
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var ids []uint
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("relation_id=? and group_identity=?", auth.ID, in.Identity).Pluck("relation_id", ids).Error
|
||||
// 标签成员在 relation_friend_in_tag,归属列是 passport_id,标签列是 tag_identity
|
||||
var ids []string
|
||||
err = impl.DBService.Model(models.FriendInTag{}).Where("passport_id=? and tag_identity=?", auth.ID, in.Identity).Pluck("friend_identity", &ids).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
@@ -24,7 +24,8 @@ func UndoPopular(ctx context.Context, in *pb.IdentRequest) (reply *pb.DataStatus
|
||||
return nil, errcode.ErrInvalidArgument
|
||||
}
|
||||
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("relation_id=? and identity=?", auth.ID, in.Identity).UpdateColumn("popular", 0).Error
|
||||
// 归属列是 passport_id,in.Identity 是好友身份(friend_relation_identity)
|
||||
err = impl.DBService.Model(models.RelationFriend{}).Where("passport_id=? and friend_relation_identity=?", auth.ID, in.Identity).UpdateColumn("popular", 0).Error
|
||||
if err != nil {
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
|
||||
Reference in New Issue
Block a user