fix: keep agency search owner scoped
This commit is contained in:
parent
424594ba02
commit
6a426ce776
@ -869,10 +869,10 @@ func TestAdminCreateAgencyControlsAppSearch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
agencies, err = svc.SearchAgencies(ctx, 902, displayID(900), 20)
|
agencies, err = svc.SearchAgencies(ctx, 902, displayID(900), 20)
|
||||||
if err != nil {
|
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 {
|
if len(agencies) != 0 {
|
||||||
t.Fatalf("created agency should be searchable by parent BD display id: %+v", agencies)
|
t.Fatalf("parent BD display id must not expand to child agencies: %+v", agencies)
|
||||||
}
|
}
|
||||||
|
|
||||||
disabledJoin, err := svc.SetAgencyJoinEnabled(ctx, hostservice.SetAgencyJoinEnabledInput{
|
disabledJoin, err := svc.SetAgencyJoinEnabled(ctx, hostservice.SetAgencyJoinEnabledInput{
|
||||||
|
|||||||
@ -42,8 +42,6 @@ func (r *Repository) SearchAgencies(ctx context.Context, command hostservice.Sea
|
|||||||
FROM agencies a
|
FROM agencies a
|
||||||
INNER JOIN users owner
|
INNER JOIN users owner
|
||||||
ON owner.app_code = a.app_code AND owner.user_id = a.owner_user_id
|
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
|
LEFT JOIN agency_memberships active_member
|
||||||
ON active_member.app_code = a.app_code
|
ON active_member.app_code = a.app_code
|
||||||
AND active_member.agency_id = a.agency_id
|
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}
|
args := []any{hostdomain.MembershipStatusActive, appcode.FromContext(ctx), country, hostdomain.AgencyStatusActive}
|
||||||
if strings.TrimSpace(command.Keyword) != "" {
|
if strings.TrimSpace(command.Keyword) != "" {
|
||||||
keyword := 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 = ?)`
|
||||||
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)
|
||||||
args = append(args, "%"+keyword+"%", int64FromKeyword(keyword), keyword, keyword)
|
|
||||||
}
|
}
|
||||||
query += `
|
query += `
|
||||||
GROUP BY
|
GROUP BY
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user