From cd4ca3c93342d55a4669cb7ea27099fcdfad6036 Mon Sep 17 00:00:00 2001 From: Chris Raible Date: Thu, 12 Oct 2023 16:47:02 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20member=20search=20ignori?= =?UTF-8?q?ng=20filters=20(#18600)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes TryGhost/Product#3792 - Previously, if you had a filter set in the members list (e.g. `status=paid`), then you searched for a member by email address, the original filter would be ignored, and any members matching the search would be returned, regardless of whether they matched the filters. Effectively, the logic was `member matches filters OR member matches search`. To make this worse, the UI still showed both the filters and the search query, leading to confusing results. - This small change to the backend logic changes the behavior to only return members that match the filter AND the search query, so if you search for a member that does not meet the current filters, they will not be returned. --- ghost/core/core/server/models/member.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ghost/core/core/server/models/member.js b/ghost/core/core/server/models/member.js index 903c77fdff..db66336d27 100644 --- a/ghost/core/core/server/models/member.js +++ b/ghost/core/core/server/models/member.js @@ -373,8 +373,10 @@ const Member = ghostBookshelf.Model.extend({ }, searchQuery: function searchQuery(queryBuilder, query) { - queryBuilder.where('members.name', 'like', `%${query}%`); - queryBuilder.orWhere('members.email', 'like', `%${query}%`); + queryBuilder.where(function () { + this.where('members.name', 'like', `%${query}%`) + .orWhere('members.email', 'like', `%${query}%`); + }); }, orderRawQuery(field, direction) {