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

UploadField doesn't validate allowed extensions with "choose existing" option #1434

Open
2 tasks done
mark-a-j-adriano opened this issue Jan 18, 2024 · 0 comments
Open
2 tasks done

Comments

@mark-a-j-adriano
Copy link

mark-a-j-adriano commented Jan 18, 2024

Module version(s) affected

2.1.3

Description

Allowed extensions validation for UploadField does not kick in when using the "choose existing" option

Browse.Asset.mp4

How to reproduce

  1. Add an upload field like this to a form:
    /** @var UploadField $logo */
    $logo = UploadField::create('Logo', 'Logo');
    $logo->setAllowedExtensions(['png', 'svg'])
        ->setAllowedMaxFileNumber(1)
        ->setUploadEnabled(false)
        ->setDescription('Accepts PNG or SVG image format.');
  2. Add a file (not png or svg) to the field using the "choose existing" option
  3. Note that the file is added to the field without raising a validation error.

NOTE the setAllowedMaxFileNumber is probably unrelated, and setUploadEnabled is not necessary.

Possible Solution

No response

Additional Context

No response

Validations

  • Check that there isn't already an issue that reports the same bug
  • Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)

Notes

  • That validation is currently handled by the upload validator - which is for validating uploaded files, not existing files
  • It would make sense for the allowed extensions validation to be triggered for existing files. It's not uncommon for business logic to be "this relation should only be files of this type" (e.g. videos only, or documents only, etc)
  • This is a fairly substantial change in logic, it should probably be introduced in a minor release rather than a patch so people can be alerted to this change via the changelog.

Acceptance criteria

  • User is blocked from selecting pre-existing files that do not match the allowed extensions.
  • All file validation rules are honoured when selecting a pre-existing file
  • The Browser upload file dialog stops you from uploading files that do not have one of the allowed extensions. (What should happen we have the default validation rules? Should all the file upload input include all the CMS allowed types?)

UX questions

  • What happens if you select a file that does not meet the validation criteria? How do we communicate to the user that they cannot select this file?
@GuySartorelli GuySartorelli changed the title UploadField validation issue when setUploadEnabled=false UploadField doesn't validate allowed extensions with "choose existing" option Jan 18, 2024
@maxime-rainville maxime-rainville added this to the Silverstripe CMS 5.3 milestone Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants