-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: backend validation does not prevent responses on hidden fields #809
Conversation
fa02efb
to
4b9ac70
Compare
4b9ac70
to
21ea9d7
Compare
@mantariksh In this PR, I limited the scope of the hidden field response check to email mode forms only; see
We discussed that validateField is not appropriate to do logic validation, and we should instead set isVisible to be true for encrypt mode. This can be done in
However for required fields, if the field is visible, we also check if the field is non-empty, for both email and encrypt mode forms - see
Basically, there is no way around this issue because fundamentally both email and encrypt mode submissions are processed in the same way today . For the scope of this PR which is to implement a bug fix for responses in email mode submissions, I suggest we stick to the more straightforward implementation which is to check for responses on hidden fields only on email mode submissions. When the sharding is done in #780, we can do away with isVisible for encrypt mode and this will solve the problem more fundamentally. For your consideration |
21ea9d7
to
2ac2006
Compare
@mantariksh as discussed, i've changed it to set isVisible = true for encrypt mode if there are responses. thanks for reviewing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main question is about deleted jasmine tests
*/ | ||
const isResponsePresentOnHiddenField = (response: FieldResponse): boolean => { | ||
if (isProcessedSingleAnswerResponse(response)) { | ||
if (!response.isVisible && response.answer.trim() !== '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will be much clearer if you return early at the start: if (response.isVisible) return false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! edited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah but then you can also remove all the `!response.isVisible. subsequently!
mobileField, | ||
'+6587654321', | ||
) | ||
mobileResponse.isVisible = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this made me realise that the tests are no longer behaving as intended. the object which we pass into getProcessedResponses
should be a FieldResponse
, not some form of ProcessedResponse
. might it be better to write a generateFieldResponse
function which doesn't include isVisible
or isUserVerified
? or even better, rename generateSingleAnswerResponse
to generateProcessedSingleAnswerResponse
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edited
src/types/response/index.ts
Outdated
@@ -25,7 +25,7 @@ export interface ICheckboxResponse extends IBaseResponse { | |||
answerArray: string[] | |||
} | |||
|
|||
export type ITableRow = string[] | |||
export type ITableRow = Array<string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we standardise to string[]
? that's how it's written everywhere else in the codebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edited
@@ -1068,89 +1058,6 @@ describe('Email Submissions Controller', () => { | |||
prepareSubmissionThenCompare(expected, done) | |||
}) | |||
|
|||
it('excludes field if isVisible is false for autoReplyData', (done) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are all these tests deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for highlighting. I removed them initially as they were invalid since they were inputting responses to hidden fields, but on review, I've instead fixed the faulty values
2ac2006
to
09a7a6c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for the comprehensive work on the tests!
*/ | ||
const isResponsePresentOnHiddenField = (response: FieldResponse): boolean => { | ||
if (isProcessedSingleAnswerResponse(response)) { | ||
if (!response.isVisible && response.answer.trim() !== '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah but then you can also remove all the `!response.isVisible. subsequently!
…t instead of using string concatenation
09a7a6c
to
4d8f079
Compare
Problem
Builds on #736
Closes #732
Closes #779
Solution
Tests