From ecf01f108e3bbcc108bcd82ce510402637b39740 Mon Sep 17 00:00:00 2001 From: Joel Coutinho Date: Fri, 31 Mar 2023 16:04:54 +0530 Subject: [PATCH] fix: bug in dashboard search query (#73) * fix: bug in dashboard search query * updates CHANGELOG and version info * reverts unnecessary changes --- .../postgresql/queries/GeneralQueries.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java b/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java index 7bb20f57..4dd9fd0e 100644 --- a/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java +++ b/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java @@ -442,7 +442,7 @@ public static AuthRecipeUserInfo[] getUsers(Start start, @NotNull Integer limit, // check if email tag is present if (dashboardSearchTags.emails != null) { - QUERY += " WHERE thirdPartyTable.email LIKE ? OR thirdPartyTable.email LIKE ?"; + QUERY += " WHERE ( thirdPartyTable.email LIKE ? OR thirdPartyTable.email LIKE ?"; queryList.add(dashboardSearchTags.emails.get(0) + "%"); queryList.add("%@" + dashboardSearchTags.emails.get(0) + "%"); @@ -452,6 +452,8 @@ public static AuthRecipeUserInfo[] getUsers(Start start, @NotNull Integer limit, queryList.add("%@" + dashboardSearchTags.emails.get(i) + "%"); } + QUERY += " )"; + } // check if providers tag is present @@ -462,12 +464,14 @@ public static AuthRecipeUserInfo[] getUsers(Start start, @NotNull Integer limit, QUERY += " WHERE "; } - QUERY += " thirdPartyTable.third_party_id LIKE ?"; + QUERY += " ( thirdPartyTable.third_party_id LIKE ?"; queryList.add(dashboardSearchTags.providers.get(0) + "%"); for (int i = 1; i < dashboardSearchTags.providers.size(); i++) { QUERY += " OR thirdPartyTable.third_party_id LIKE ?"; queryList.add(dashboardSearchTags.providers.get(i) + "%"); } + + QUERY += " )"; } // check if we need to append this to an existing search query @@ -493,7 +497,7 @@ public static AuthRecipeUserInfo[] getUsers(Start start, @NotNull Integer limit, // check if email tag is present if (dashboardSearchTags.emails != null) { - QUERY = QUERY + " WHERE passwordlessTable.email LIKE ? OR passwordlessTable.email LIKE ?"; + QUERY = QUERY + " WHERE ( passwordlessTable.email LIKE ? OR passwordlessTable.email LIKE ?"; queryList.add(dashboardSearchTags.emails.get(0) + "%"); queryList.add("%@" + dashboardSearchTags.emails.get(0) + "%"); for (int i = 1; i < dashboardSearchTags.emails.size(); i++) { @@ -501,6 +505,8 @@ public static AuthRecipeUserInfo[] getUsers(Start start, @NotNull Integer limit, queryList.add(dashboardSearchTags.emails.get(i) + "%"); queryList.add("%@" + dashboardSearchTags.emails.get(i) + "%"); } + + QUERY += " )"; } // check if phone tag is present @@ -512,20 +518,14 @@ public static AuthRecipeUserInfo[] getUsers(Start start, @NotNull Integer limit, QUERY += " WHERE "; } - QUERY += " passwordlessTable.phone_number LIKE ?"; - if (dashboardSearchTags.phoneNumbers.get(0).startsWith("+")) { - queryList.add(dashboardSearchTags.phoneNumbers.get(0) + "%"); - } else { - queryList.add("+" + dashboardSearchTags.phoneNumbers.get(0) + "%"); - } + QUERY += " ( passwordlessTable.phone_number LIKE ?"; + queryList.add(dashboardSearchTags.phoneNumbers.get(0) + "%"); for (int i = 1; i < dashboardSearchTags.phoneNumbers.size(); i++) { QUERY += " OR passwordlessTable.phone_number LIKE ?"; - if (dashboardSearchTags.phoneNumbers.get(i).startsWith("+")) { - queryList.add(dashboardSearchTags.phoneNumbers.get(i) + "%"); - } else { - queryList.add("+" + dashboardSearchTags.phoneNumbers.get(i) + "%"); - } + queryList.add(dashboardSearchTags.phoneNumbers.get(i) + "%"); } + + QUERY += " )"; } // check if we need to append this to an existing search query