Lint and change status code to 400 when searching on invalid fields
This commit is contained in:
parent
e16cc26781
commit
66f219d778
|
@ -26,10 +26,10 @@ import {
|
||||||
migrations,
|
migrations,
|
||||||
platform,
|
platform,
|
||||||
tenancy,
|
tenancy,
|
||||||
|
db,
|
||||||
} from "@budibase/backend-core"
|
} from "@budibase/backend-core"
|
||||||
import { checkAnyUserExists } from "../../../utilities/users"
|
import { checkAnyUserExists } from "../../../utilities/users"
|
||||||
import { isEmailConfigured } from "../../../utilities/email"
|
import { isEmailConfigured } from "../../../utilities/email"
|
||||||
import { removeKeyNumbering } from "@budibase/backend-core/src/db"
|
|
||||||
|
|
||||||
const MAX_USERS_UPLOAD_LIMIT = 1000
|
const MAX_USERS_UPLOAD_LIMIT = 1000
|
||||||
|
|
||||||
|
@ -195,13 +195,13 @@ export const search = async (ctx: Ctx<SearchUsersRequest>) => {
|
||||||
if (filters && typeof filters === "object") {
|
if (filters && typeof filters === "object") {
|
||||||
for (let [field, value] of Object.entries(filters)) {
|
for (let [field, value] of Object.entries(filters)) {
|
||||||
delete filters[field]
|
delete filters[field]
|
||||||
filters[removeKeyNumbering(field)] = value
|
filters[db.removeKeyNumbering(field)] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Validate we aren't trying to search on any illegal fields
|
// Validate we aren't trying to search on any illegal fields
|
||||||
if (!userSdk.core.isSupportedUserSearch(body.query)) {
|
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -623,7 +623,7 @@ describe("/api/global/users", () => {
|
||||||
{
|
{
|
||||||
query: { equal: { firstName: user.firstName } },
|
query: { equal: { firstName: user.firstName } },
|
||||||
},
|
},
|
||||||
{ status: 501 }
|
{ status: 400 }
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue