From c4780fa3e581f262fec704c8db61c6c72a51bc63 Mon Sep 17 00:00:00 2001 From: aichy126 <16996097+aichy126@users.noreply.github.com> Date: Fri, 17 Mar 2023 10:54:47 +0800 Subject: [PATCH 1/2] update short id --- internal/controller/answer_controller.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.go index 8e4ca92d..58fd56c4 100644 --- a/internal/controller/answer_controller.go +++ b/internal/controller/answer_controller.go @@ -110,6 +110,7 @@ func (ac *AnswerController) Add(ctx *gin.Context) { if handler.BindAndCheck(ctx, req) { return } + req.QuestionID = uid.DeShortID(req.QuestionID) req.UserID = middleware.GetLoginUserIDFromContext(ctx) can, err := ac.rankService.CheckOperationPermission(ctx, req.UserID, permission.AnswerAdd, "") From d7d652040c773034bc71275c07fb13c6fb2b2408 Mon Sep 17 00:00:00 2001 From: aichy126 <16996097+aichy126@users.noreply.github.com> Date: Fri, 17 Mar 2023 10:54:54 +0800 Subject: [PATCH 2/2] update short id --- internal/service/answer_service.go | 3 ++- internal/service/notification_common/notification.go | 2 +- internal/service/rank/rank_service.go | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/service/answer_service.go b/internal/service/answer_service.go index 1860bf7d..baeaca00 100644 --- a/internal/service/answer_service.go +++ b/internal/service/answer_service.go @@ -22,6 +22,7 @@ import ( "github.com/answerdev/answer/internal/service/revision_common" usercommon "github.com/answerdev/answer/internal/service/user_common" "github.com/answerdev/answer/pkg/encryption" + "github.com/answerdev/answer/pkg/uid" "github.com/segmentfault/pacman/errors" "github.com/segmentfault/pacman/log" ) @@ -159,7 +160,7 @@ func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq) ( if err != nil { log.Error("IncreaseAnswerCount error", err.Error()) } - err = as.questionCommon.UpdateLastAnswer(ctx, req.QuestionID, insertData.ID) + err = as.questionCommon.UpdateLastAnswer(ctx, req.QuestionID, uid.DeShortID(insertData.ID)) if err != nil { log.Error("UpdateLastAnswer error", err.Error()) } diff --git a/internal/service/notification_common/notification.go b/internal/service/notification_common/notification.go index 1a14c466..eb148cd4 100644 --- a/internal/service/notification_common/notification.go +++ b/internal/service/notification_common/notification.go @@ -198,7 +198,7 @@ func (ns *NotificationCommon) SendNotificationToAllFollower(ctx context.Context, } condObjectID := msg.ObjectID if len(questionID) > 0 { - condObjectID = questionID + condObjectID = uid.DeShortID(questionID) } userIDs, err := ns.followRepo.GetFollowUserIDs(ctx, condObjectID) if err != nil { diff --git a/internal/service/rank/rank_service.go b/internal/service/rank/rank_service.go index dac7df20..56ad07ca 100644 --- a/internal/service/rank/rank_service.go +++ b/internal/service/rank/rank_service.go @@ -15,6 +15,7 @@ import ( "github.com/answerdev/answer/internal/service/role" usercommon "github.com/answerdev/answer/internal/service/user_common" "github.com/answerdev/answer/pkg/htmltext" + "github.com/answerdev/answer/pkg/uid" "github.com/segmentfault/pacman/errors" "github.com/segmentfault/pacman/log" "xorm.io/xorm" @@ -124,6 +125,7 @@ func (rs *RankService) CheckOperationPermissions(ctx context.Context, userID str // CheckOperationObjectOwner check operation object owner func (rs *RankService) CheckOperationObjectOwner(ctx context.Context, userID, objectID string) bool { + objectID = uid.DeShortID(objectID) objectInfo, err := rs.objectInfoService.GetInfo(ctx, objectID) if err != nil { log.Error(err)