Skip to content
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(encrypt-submission): shift encrypt mode form guard higher up the pipeline #1929

Merged
merged 3 commits into from
May 20, 2021

Conversation

yong-jie
Copy link
Member

Problem

The guard to prevent submisison of non-storage mode forms in storage mode submission endpoint is located very low in the pipeline, when it should have been one of the first checks made.

Reordering this above will also help reflect the typing of the form object accurately, earlier in the pipeline.

Solution

Copy paste, with changes in wording of the log messaging

Copy link
Contributor

@mantariksh mantariksh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually might it be better to use EncryptSubmissionService.checkFormIsEncryptMode, and use mapRouteError to get the status code and error message?

advantages are

  1. a step towards keeping all the status codes and error messages in one place
  2. easier to chain Results in future if someone wants to clean up this controller, like @seaerchin did for submitEmailModeForm

And move higher up the pipeline so that the `form` variable has the
new type.
@yong-jie
Copy link
Member Author

good idea, i just switched the approach and moved it higher up the pipeline so that the form variable has the correct type

Comment on lines +79 to +93
const checkFormIsEncryptModeResult = checkFormIsEncryptMode(formResult.value)
if (checkFormIsEncryptModeResult.isErr()) {
logger.error({
message:
'Trying to submit non-encrypt mode submission on encrypt-form submission endpoint',
meta: logMeta,
})
const { statusCode, errorMessage } = mapRouteError(
checkFormIsEncryptModeResult.error,
)
return res.status(statusCode).json({
message: errorMessage,
})
}
const form = checkFormIsEncryptModeResult.value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually i think neverthrow solves this problem of repeated error checking - we can just chain this into the next method and be confident that the form is already encrypted!

then, the mapErr will be applied to the result of the whole expression (inclusive) of this! we could do a pass through on the err (using mapErr) so that the type is preserved but logs are still present too.

idk if it's beyond the scope of this PR but yea, just something to think about, especially because lines 70 - 186 is essentially just checking the form

Copy link
Member Author

@yong-jie yong-jie May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review! yup the end goal will be definitely to refactor the whole pipeline to use the same map/mapErr pattern as the email-submission endpoint. but that should be left for later after all the upcoming work on the encrypt-submission pipeline is completed

Copy link
Contributor

@karrui karrui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@yong-jie yong-jie merged commit 64e7c8b into develop May 20, 2021
@yong-jie yong-jie deleted the reorder-encrypt-submission-guard branch May 20, 2021 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants