Skip to content

Improve attachment validation on the front-end#10118

Merged
marcaaron merged 19 commits into
mainfrom
tgolen-attachment-validation
Jul 28, 2022
Merged

Improve attachment validation on the front-end#10118
marcaaron merged 19 commits into
mainfrom
tgolen-attachment-validation

Conversation

@tgolen

@tgolen tgolen commented Jul 26, 2022

Copy link
Copy Markdown
Contributor

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

@marcaaron marcaaron left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/components/AttachmentModal.js Outdated
Comment thread src/components/AttachmentModal.js Outdated
Comment thread src/components/AttachmentModal.js
return;
}

if (file instanceof File) {

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/pages/home/report/ReportActionItem.js
Comment thread src/pages/home/report/ReportActionItemMessageEdit.js Outdated
@tgolen

tgolen commented Jul 27, 2022

Copy link
Copy Markdown
Contributor Author

Updated

Comment thread src/components/AttachmentModal.js Outdated
Comment on lines +186 to +188
if (!file) {
return;
}

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/components/AttachmentModal.js Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

OSBotify commented Aug 1, 2022

Copy link
Copy Markdown
Contributor

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

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

@OSBotify

OSBotify commented Aug 4, 2022

Copy link
Copy Markdown
Contributor

🚀 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
Copy Markdown
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

tgolen commented Aug 9, 2022

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor

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

@tgolen

tgolen commented Aug 10, 2022

Copy link
Copy Markdown
Contributor Author

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

@mountiny

Copy link
Copy Markdown
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

isModalOpen: false,
isConfirmModalOpen: false,
isAttachmentInvalid: false,
attachmentInvalidReasonTitle: null,

Copy link
Copy Markdown
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
Copy Markdown
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