-
Notifications
You must be signed in to change notification settings - Fork 5
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: Validate max file size for attachments #149
Changes from all commits
eeb63b7
cd44fba
d3cd277
35cc63b
009961e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { QuestionnaireItem } from '../../../../types/fhir'; | ||
import { getMaxSizeExtensionValue } from '../../../../util/extension'; | ||
|
||
describe('Attachment form component', () => { | ||
const questionExtention: QuestionnaireItem = { | ||
linkId: '4c71df6e-d743-46ba-d81f-f62777ffddb4', | ||
type: 'attachment', | ||
text: '5mb', | ||
extension: [ | ||
{ | ||
url: 'http://hl7.org/fhir/StructureDefinition/maxSize', | ||
valueDecimal: 5, | ||
}, | ||
], | ||
}; | ||
it('Should give back right value from extention in MB', () => { | ||
const test = getMaxSizeExtensionValue(questionExtention); | ||
expect(test).toBe(5); | ||
}); | ||
const question: QuestionnaireItem = { | ||
linkId: '4c71df6e-d743-46ba-d81f-f62777ffddb4', | ||
type: 'attachment', | ||
text: 'No extention', | ||
}; | ||
it('Should fail to undefined without extention', () => { | ||
const test = getMaxSizeExtensionValue(question); | ||
expect(test).toBe(undefined); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import { sizeIsValid, mimeTypeIsValid } from '@helsenorge/file-upload/components | |
import Validation, { ValidationProps } from '@helsenorge/form/components/form/validation'; | ||
|
||
import constants, { VALID_FILE_TYPES } from '../../../constants'; | ||
import { getValidationTextExtension } from '../../../util/extension'; | ||
import { getMaxSizeExtensionValue, getValidationTextExtension } from '../../../util/extension'; | ||
import { Resources } from '../../../util/resources'; | ||
|
||
interface Props { | ||
|
@@ -65,7 +65,12 @@ const attachmentHtml: React.SFC<Props & ValidationProps> = ({ | |
children, | ||
...other | ||
}) => { | ||
const maxFilesize = attachmentMaxFileSize ? attachmentMaxFileSize : constants.MAX_FILE_SIZE; | ||
const maxValueFromQuestionaire = getMaxSizeExtensionValue(item); | ||
const maxFilesize = maxValueFromQuestionaire | ||
? maxValueFromQuestionaire * 1024 * 1024 | ||
: attachmentMaxFileSize | ||
? attachmentMaxFileSize | ||
: constants.MAX_FILE_SIZE; | ||
const validFileTypes = attachmentValidTypes ? attachmentValidTypes : VALID_FILE_TYPES; | ||
const deleteText = resources ? resources.deleteAttachmentText : undefined; | ||
|
||
|
@@ -118,7 +123,7 @@ function getErrorMessage( | |
if (!mimeTypeIsValid(file, validFileTypes)) { | ||
return resources.validationFileType; | ||
} else if (!sizeIsValid(file, maxFileSize)) { | ||
return resources.validationFileMax; | ||
return resources.validationFileMax.replace('25', (maxFileSize / 1024 / 1024).toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Er ikke helt sikker at det er lurt at gjøre det hit. Er det ikke HN-Skjema sender i riktig format til refero. Kanskje det trenger ikke gjøre noe endring i feilmeldingen There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vi har denne i HN-Skjema There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enig, da tror jeg har forstått det riktitg, Slik jeg forsøker å løse nå, så bruker jeg bare |
||
} | ||
} | ||
|
||
|
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.
Det er ikke veldig viktig men man kan bruke
import itemType from '../constants/itemType';
type: itemType.ATTATCHMENT