1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00

Lint and change status code to 400 when searching on invalid fields

This commit is contained in:
Andrew Kingston 2023-12-12 10:26:48 +00:00
parent e16cc26781
commit 66f219d778
2 changed files with 4 additions and 4 deletions

View file

@ -26,10 +26,10 @@ import {
migrations,
platform,
tenancy,
db,
} from "@budibase/backend-core"
import { checkAnyUserExists } from "../../../utilities/users"
import { isEmailConfigured } from "../../../utilities/email"
import { removeKeyNumbering } from "@budibase/backend-core/src/db"
const MAX_USERS_UPLOAD_LIMIT = 1000
@ -195,13 +195,13 @@ export const search = async (ctx: Ctx<SearchUsersRequest>) => {
if (filters && typeof filters === "object") {
for (let [field, value] of Object.entries(filters)) {
delete filters[field]
filters[removeKeyNumbering(field)] = value
filters[db.removeKeyNumbering(field)] = value
}
}
}
// Validate we aren't trying to search on any illegal fields
if (!userSdk.core.isSupportedUserSearch(body.query)) {
ctx.throw(501, "Can only search by string.email or equal._id")
ctx.throw(400, "Can only search by string.email or equal._id")
}
}

View file

@ -623,7 +623,7 @@ describe("/api/global/users", () => {
{
query: { equal: { firstName: user.firstName } },
},
{ status: 501 }
{ status: 400 }
)
})