Fix cryptic file validation errors#9663
Conversation
|
This is a great improvement on what we have for sure!
As far as I could find is the only one with mixed formats.
(Mind that the help text doesn't correspond and talks about images, but that's out of the scope of the current PR) |
Previously this only applied to the validators run for files attached through the uploaders. Which is problematic e.g. for CSV files that we just upload and process without an uploader in-between.
Previously it was always using the defaults instead of the settings configured for the target organization attached to the record.
The votings census file upload broke after modifying the file validation logic as it was missing the current participatory space where it fetches the organization from.
In order to fetch the correct file extensions in each situation for the dynamic upload errors, we need to define a proxy record to pass the correct upload context for the validations.
In order to show the file extensions similarly in the help texts and the errors, sort them at the humanizer which produces the extensions list for the help texts.
|
@andreslucena All issues fixed that I could fix in this PR. The rest will be fixed by another PR #9623. See explanations below.
Done. Also changed the other similar error messages to match this format.
The mixed format is because Decidim produces unknown MIME types currently. E.g. This has been a persistent issue in Decidim for years but I am fixing it in another PR #9623. In particular it is this line that will fix this issue: Do note that this same issue will still persist in case the system administrator has configured MIME types unknown for MiniMime. But I would see that as misconfiguration rather than a bug, and it'd be good to show those "extra" unknown MIME types for the user in case that happens to make it easier to identify potential issues regarding those.
This was because the file validation wasn't context aware whether the validation is happening at the admin panel or the participant side of the system which can have different allowed extensions through the system settings. I have fixed this issue in the latest revisions.
This was because initially I only applied these changes to the upload validations happening for files that are attached to the records through uploaders. This was not applied in case you just used I had to do a bit of a "hack" to also fix the messages for such direct validations by overriding one method from |
Great! I'll check that one after merging this one.
Ok, I agree. |
andreslucena
left a comment
There was a problem hiding this comment.
I've rechecked all my comments and are all fixed 👍🏽 👍🏽
Code-wise everything is great, documented, and tested. 💯
* feature/redesign-turbo: Install turbo-rails Fix incorrect expecations after change of allowed file extensions (#9877) Update `@joeattardi/emoji-button` to `@picmo/popup-picker` (#9667) Address Crowdin feedback (#9678) Fix cryptic file validation errors (#9663) Fix disappearing sub-lists in rich text editors (#9867) Implement authorization data recovery for deleted users (#9463) Redesigned: admin bar (#9874)
* Fix cryptic file validation errors * Improve the content type validator and add method documentation * Add content type validator spec for denylist case * Fix the file definition within the spec * Fix specs broken because of the message changes * Update the error message for invalid file content type as per review * Fix the obfuscated error messages also for file content type validators Previously this only applied to the validators run for files attached through the uploaders. Which is problematic e.g. for CSV files that we just upload and process without an uploader in-between. * Add spec for the customized file content type validator * Get the extension allowlist through the uploader if available * Fix the extension_allowlist translation * Move the extension allowlist translation to the correct module * Fetch the extension allowlist through the correct recrod Previously it was always using the defaults instead of the settings configured for the target organization attached to the record. * Pass the context to the form records assigned to PassthruValidator The votings census file upload broke after modifying the file validation logic as it was missing the current participatory space where it fetches the organization from. * Pass the correct upload context for the dynamic file validations In order to fetch the correct file extensions in each situation for the dynamic upload errors, we need to define a proxy record to pass the correct upload context for the validations. * Sort the file extensions at the FileValidatorHumanizer In order to show the file extensions similarly in the help texts and the errors, sort them at the humanizer which produces the extensions list for the help texts. * Fix file not attached to organization with attachment proxy * Normalize locales * Use delegate method instead of extending SimpleDelegator



🎩 What? Why?
Currently the file validation messages are rather cryptic for the general user because they are showing the content type matching pattern regular expressions converted into strings.
To make it understandable for the general public, we want to show the file extensions instead of the content types.
📌 Related Issues
Testing
.zipfile is not allowed by default