修复(#128): 修复家庭成员邀请流水可见性
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -113,12 +113,17 @@ func (l *GetInviteRecordsLogic) GetInviteRecords(req *types.GetInviteRecordsRequ
|
|||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query orders failed: %v", err.Error())
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query orders failed: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
visibleUserIdSet := make(map[int64]struct{}, len(visibleUserIds))
|
||||||
|
for _, userId := range visibleUserIds {
|
||||||
|
visibleUserIdSet[userId] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
allRecords := make([]types.InviteRecord, 0, len(parsedLogs))
|
allRecords := make([]types.InviteRecord, 0, len(parsedLogs))
|
||||||
for _, parsed := range parsedLogs {
|
for _, parsed := range parsedLogs {
|
||||||
content := parsed.content
|
content := parsed.content
|
||||||
logItem := parsed.log
|
logItem := parsed.log
|
||||||
orderInfo, hasOrder := orders[content.OrderNo]
|
orderInfo, hasOrder := orders[content.OrderNo]
|
||||||
if !l.canViewInviteRecord(u.Id, logItem.ObjectId, hasOrder, orderInfo) {
|
if !l.canViewInviteRecord(u.Id, logItem.ObjectId, visibleUserIdSet, hasOrder, orderInfo) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,17 +182,17 @@ func (l *GetInviteRecordsLogic) resolveInviteRecordVisibleUserIds(currentUserId
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetInviteRecordsLogic) canViewInviteRecord(currentUserId, logObjectId int64, hasOrder bool, orderInfo inviteOrderUser) bool {
|
func (l *GetInviteRecordsLogic) canViewInviteRecord(currentUserId, logObjectId int64, visibleUserIds map[int64]struct{}, hasOrder bool, orderInfo inviteOrderUser) bool {
|
||||||
|
if _, ok := visibleUserIds[logObjectId]; !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if logObjectId == currentUserId {
|
if logObjectId == currentUserId {
|
||||||
if hasOrder {
|
if hasOrder {
|
||||||
return orderInfo.UserId == currentUserId || orderInfo.RefererId == currentUserId
|
return orderInfo.UserId == currentUserId || orderInfo.RefererId == currentUserId
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if !hasOrder {
|
return true
|
||||||
return false
|
|
||||||
}
|
|
||||||
return orderInfo.UserId == currentUserId && orderInfo.SubscriptionUserId == logObjectId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func normalizeInviteRecordsPagination(req *types.GetInviteRecordsRequest) {
|
func normalizeInviteRecordsPagination(req *types.GetInviteRecordsRequest) {
|
||||||
|
|||||||
@@ -123,6 +123,33 @@ func TestGetInviteRecordsFamilyMemberSeesOwnerGiftLog(t *testing.T) {
|
|||||||
assertInviteRecordsExpectations(t, mock)
|
assertInviteRecordsExpectations(t, mock)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetInviteRecordsFamilyMemberSeesAllOwnerGiftLogs(t *testing.T) {
|
||||||
|
svcCtx, mock, cleanup := newInviteRecordsTestSvc(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
expectInviteRecordsFamilyMember(t, mock, 51637, 510)
|
||||||
|
mock.ExpectQuery("SELECT id, object_id, content").
|
||||||
|
WithArgs(34, int64(51637), int64(510), "邀请赠送").
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"id", "object_id", "content", "created_at"}).
|
||||||
|
AddRow(6, 510, `{"order_no":"owner-order","amount":7,"remark":"邀请赠送"}`, 1779934630000))
|
||||||
|
mock.ExpectQuery("SELECT `order`.order_no, `order`.user_id, `order`.subscription_user_id, invitee.referer_id FROM `order`").
|
||||||
|
WithArgs("owner-order").
|
||||||
|
WillReturnRows(sqlmock.NewRows([]string{"order_no", "user_id", "subscription_user_id", "referer_id"}).AddRow("owner-order", 571, 571, 510))
|
||||||
|
|
||||||
|
resp, err := NewGetInviteRecordsLogic(inviteRecordsContext(51637, 0), svcCtx).GetInviteRecords(&types.GetInviteRecordsRequest{Page: 1, Size: 10})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("GetInviteRecords returned error: %v", err)
|
||||||
|
}
|
||||||
|
assertInviteRecordResponse(t, resp, types.InviteRecord{
|
||||||
|
Role: inviteRecordRoleInviter,
|
||||||
|
PeerHash: hash.InvitePeerHash(571),
|
||||||
|
GiftDays: 7,
|
||||||
|
OrderNo: "owner-order",
|
||||||
|
CreatedAt: 1779934630000,
|
||||||
|
})
|
||||||
|
assertInviteRecordsExpectations(t, mock)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetInviteRecordsOwnerDoesNotSeeMemberGiftLog(t *testing.T) {
|
func TestGetInviteRecordsOwnerDoesNotSeeMemberGiftLog(t *testing.T) {
|
||||||
svcCtx, mock, cleanup := newInviteRecordsTestSvc(t)
|
svcCtx, mock, cleanup := newInviteRecordsTestSvc(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|||||||
Reference in New Issue
Block a user