From 6a426ce776e0b6d50d67ad5df7e2d75063fd5c79 Mon Sep 17 00:00:00 2001 From: zhx Date: Wed, 1 Jul 2026 19:28:26 +0800 Subject: [PATCH] fix: keep agency search owner scoped --- .../user-service/internal/service/host/service_test.go | 6 +++--- .../user-service/internal/storage/mysql/host/queries.go | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/services/user-service/internal/service/host/service_test.go b/services/user-service/internal/service/host/service_test.go index c8a9e770..f5df04a1 100644 --- a/services/user-service/internal/service/host/service_test.go +++ b/services/user-service/internal/service/host/service_test.go @@ -869,10 +869,10 @@ func TestAdminCreateAgencyControlsAppSearch(t *testing.T) { } agencies, err = svc.SearchAgencies(ctx, 902, displayID(900), 20) if err != nil { - t.Fatalf("SearchAgencies by parent BD display id failed: %v", err) + t.Fatalf("SearchAgencies by non-owner parent BD display id failed: %v", err) } - if len(agencies) != 1 || agencies[0].AgencyID != created.Agency.AgencyID { - t.Fatalf("created agency should be searchable by parent BD display id: %+v", agencies) + if len(agencies) != 0 { + t.Fatalf("parent BD display id must not expand to child agencies: %+v", agencies) } disabledJoin, err := svc.SetAgencyJoinEnabled(ctx, hostservice.SetAgencyJoinEnabledInput{ diff --git a/services/user-service/internal/storage/mysql/host/queries.go b/services/user-service/internal/storage/mysql/host/queries.go index d3fd240f..893610e3 100644 --- a/services/user-service/internal/storage/mysql/host/queries.go +++ b/services/user-service/internal/storage/mysql/host/queries.go @@ -42,8 +42,6 @@ func (r *Repository) SearchAgencies(ctx context.Context, command hostservice.Sea FROM agencies a INNER JOIN users owner ON owner.app_code = a.app_code AND owner.user_id = a.owner_user_id - LEFT JOIN users parent_bd - ON parent_bd.app_code = a.app_code AND parent_bd.user_id = a.parent_bd_user_id LEFT JOIN agency_memberships active_member ON active_member.app_code = a.app_code AND active_member.agency_id = a.agency_id @@ -57,9 +55,8 @@ func (r *Repository) SearchAgencies(ctx context.Context, command hostservice.Sea args := []any{hostdomain.MembershipStatusActive, appcode.FromContext(ctx), country, hostdomain.AgencyStatusActive} if strings.TrimSpace(command.Keyword) != "" { keyword := strings.TrimSpace(command.Keyword) - // Host 申请页里运营常按 BD 短号找“这个 BD 下面的公会”,因此关键字同时匹配 owner 和 parent BD。 - query += ` AND (a.name LIKE ? OR a.agency_id = ? OR owner.current_display_user_id = ? OR parent_bd.current_display_user_id = ?)` - args = append(args, "%"+keyword+"%", int64FromKeyword(keyword), keyword, keyword) + query += ` AND (a.name LIKE ? OR a.agency_id = ? OR owner.current_display_user_id = ?)` + args = append(args, "%"+keyword+"%", int64FromKeyword(keyword), keyword) } query += ` GROUP BY