fix: keep agency search owner scoped

This commit is contained in:
zhx 2026-07-01 19:28:26 +08:00
parent 424594ba02
commit 6a426ce776
2 changed files with 5 additions and 8 deletions

View File

@ -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{

View File

@ -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