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

Improve attachment validation on the front-end #10118

Merged
merged 19 commits into from
Jul 28, 2022

Conversation

tgolen
Copy link
Contributor

@tgolen tgolen commented Jul 26, 2022

Adds validation for minimum file size and file type.

Fixed Issues

$ #10050

Tests

  1. Upload a file that is too small (less than 240 bytes). Here is one you can use:
    icon16
  2. Verify that you get a too small error message
  3. Upload an image that is too larger (more than 50 MB). You can download this high-res image from here: https://effigis.com/wp-content/themes/effigis_2014/img/RapidEye_RapidEye_5m_RGB_Altotting_Germany_Agriculture_and_Forestry_2009MAY17_8bits_sub_r_2.jpg
  4. Verify that you get a too big error message
  5. Make a copy of that small file from above and change it's extension to something invalid (like .x) and upload it
  6. Verify that you get a wrong file type error message
  7. Upload proper files and verify they upload properly
  • Verify that no errors appear in the JS console

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

Screenshots

Web

2022-07-26_14-55-51

2022-07-26_14-55-37

2022-07-26_14-53-07

Mobile Web

2022-07-26_14-58-14

2022-07-26_14-58-02

2022-07-26_14-58-30

Desktop

2022-07-26_15-01-26

2022-07-26_15-01-38

2022-07-26_15-01-51

iOS

I'm struggling to get iOS running (see slack)

Android

I couldn't really find any way to test the errors because it's difficult to force those kind of size images on the emulator. I tried downloading some images from the web, but I still had trouble finding them to upload into the app.

@tgolen tgolen self-assigned this Jul 26, 2022
@tgolen tgolen requested a review from marcaaron July 26, 2022 20:43
@tgolen tgolen marked this pull request as ready for review July 26, 2022 21:26
@tgolen tgolen requested a review from a team as a code owner July 26, 2022 21:26
@melvin-bot melvin-bot bot requested review from marcochavezf and removed request for a team July 26, 2022 21:27
Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

Nice changes overall and liking the cleanup - found a few style / consistency things.

src/components/AttachmentModal.js Outdated Show resolved Hide resolved
src/components/AttachmentModal.js Outdated Show resolved Hide resolved
src/components/AttachmentModal.js Show resolved Hide resolved
return;
}

if (file instanceof File) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of curious whether the File is going to have a size property. Might be good to test on native and log out the value just to be sure (can help with this if you're running into issues).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can test this out on Android. I'm 100% certain File will always have size, but good to verify anyway.

src/pages/home/report/ReportActionItem.js Show resolved Hide resolved
src/pages/home/report/ReportActionItemMessageEdit.js Outdated Show resolved Hide resolved
@tgolen
Copy link
Contributor Author

tgolen commented Jul 27, 2022

Updated

src/components/AttachmentModal.js Outdated Show resolved Hide resolved
Comment on lines +186 to +188
if (!file) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: I wonder when file is empty and if it's an uncovered edge case.

If it's empty because of an error, I think we should move this condition to isValidFile function and populate attachmentInvalidReasonTitle with this.props.translate('attachmentPicker.attachmentError').

Or just log something using Log.hmmm.

thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't really think it's a valid edge case for file to be empty, but it protects fatal errors in the case that it is. I'd probably be more comfortable removing this condition entirely. We seem to be paranoid about this object, and I'm not 100% why.

tgolen and others added 2 commits July 27, 2022 14:31
Co-authored-by: Marco Chávez <marcochavezf@gmail.com>
Co-authored-by: Marco Chávez <marcochavezf@gmail.com>
@marcaaron marcaaron self-requested a review July 28, 2022 00:29
&& Str.isPDF(file.name || this.props.translate('attachmentView.unknownFilename'))
)
)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This just needs a few more indents and it will be ready for merge :trollface:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, the logic is already melting my brain :D

@marcaaron marcaaron merged commit b4232d8 into main Jul 28, 2022
@marcaaron marcaaron deleted the tgolen-attachment-validation branch July 28, 2022 00:34
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented Aug 1, 2022

🚀 Deployed to staging by @marcaaron in version: 1.1.87-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 failure ❌
🍎 iOS 🍎 failure ❌
🕸 web 🕸 failure ❌

@OSBotify
Copy link
Contributor

OSBotify commented Aug 4, 2022

🚀 Deployed to production by @yuwenmemon in version: 1.1.87-9 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@gladiator-1
Copy link
Contributor

You didn't add video extensions ('mp4,mov,...'), no one can send a video file now, Is it ok?

ALLOWED_EXTENSIONS: ['jpg', 'jpeg', 'png', 'gif', 'pdf', 'html', 'txt', 'rtf', 'doc', 'docx', 'htm', 'tiff', 'tif', 'xml'],

@tgolen
Copy link
Contributor Author

tgolen commented Aug 9, 2022

Hm, that was the list of extensions that the server was preventing. You could try allowing that extension, and then see if the server allows it to be uploaded. In that case, I must have missed a few extensions and can add them. Would you mind trying that out @gladiator-1 ?

@gladiator-1
Copy link
Contributor

@tgolen I tried it in the morning and it worked fine.

@tgolen
Copy link
Contributor Author

tgolen commented Aug 10, 2022

OK, I can add mov and mp4 to the list. Any others?

@mountiny
Copy link
Contributor

Per the checklist noting, that there was a bug regression coming from this PR (or this took the bug from previous issues). The text of the error messages in modal should have a proper punctuation in the end (the main message of the error, not the title). Keep that in mind for future, thanks! #14200

@@ -71,15 +72,17 @@ class AttachmentModal extends PureComponent {

this.state = {
isModalOpen: false,
isConfirmModalOpen: false,
isAttachmentInvalid: false,
attachmentInvalidReasonTitle: null,
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use empty String for attachmentInvalidReasonTitle because Confirm modal accepts string as title but we pass null which cause in this issue. Fixed it here by providing empty String.

Comment on lines -201 to +267
title={this.props.translate('attachmentPicker.attachmentTooLarge')}
title={this.state.attachmentInvalidReasonTitle}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change causes a regression #22665. We just reverted back the logic i.e store translationKey in the state instead of value. Translated while passing

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.

8 participants