magento-lts icon indicating copy to clipboard operation
magento-lts copied to clipboard

Customization for _getUploadRoot and _getAllowedExtensions in Mage_Adminhtml_Model_System_Config_Backend_File

Open eneiasramos opened this issue 1 year ago • 7 comments

…lowedExtensions

Description (*)

Here we have the implementation of 2 functionalities:

1 - Add validation for allowed extensions when uploading files.

today:

<upload_dir config="system/filesystem/media" scope_info="1">sales/store/logo</upload_dir>

new:

<upload_dir allowed_extensions="png,jpg,jpeg,gif" config="system/filesystem/media" scope_info="1">sales/store/logo</upload_dir>

2 - Add validation to the config's attribute in upload_dir's tag (not used today). Also the possibility of customizing it. Example:

today:

<upload_dir config="system/filesystem/media" scope_info="1">docs/pdf</upload_dir>

new:

<upload_dir allowed_extensions="pdf" config="system/filesystem/var" scope_info="1">docs/pdf</upload_dir>

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes OpenMage/magento-lts#<issue_number>

Manual testing scenarios (*)

  1. ...
  2. ...

Questions or comments

Contribution checklist (*)

  • [ ] Pull request has a meaningful description of its purpose
  • [ ] All commits are accompanied by meaningful commit messages
  • [ ] All automated tests passed successfully (all builds are green)
  • [ ] Add yourself to contributors list

eneiasramos avatar Apr 08 '24 16:04 eneiasramos

@eneiasramos could you please write a real title and description? thanks!

fballiano avatar Apr 08 '24 16:04 fballiano

@eneiasramos could you please write a real title and description? thanks!

Sorry I forgot that my dear :smile_cat:

eneiasramos avatar Apr 08 '24 16:04 eneiasramos

@fballiano done my dear!

eneiasramos avatar Apr 08 '24 17:04 eneiasramos

@Flyingmana can you help me here? I'm not sure I understand how to test this

fballiano avatar May 02 '24 09:05 fballiano

will have a look on the weekend

Flyingmana avatar May 02 '24 10:05 Flyingmana

Images can use the backend_model Mage_Adminhtml_Model_System_Config_Backend_Image, this will allow uploading of 'jpg', 'jpeg', 'gif', 'png' already. No need to have that in the base class.

As for the path I don't follow the changes here. Can you explain some more of what you are trying to do?

If you only want to allow a specific file extension I would provide a class that extends Mage_Adminhtml_Model_System_Config_Backend_File and override protected function _getAllowedExtensions. (see Mage_Adminhtml_Model_System_Config_Backend_Image as an example)

pquerner avatar May 02 '24 10:05 pquerner

Ok, for the how to Test part.

have a config which overwrites the system.xml for image

There by adding the new allowed_extensions attribute it should be able to control which ones are allowed to upload.

Although, its probably more for the logo in app/code/core/Mage/Sales/etc/system.xml not the placeholder one in my screenshot.

What Iam not sure about is, what the exact use case or benefit should be.

Also as this part is a bit complex, I would would like to require a phpunit test for this parts

Flyingmana avatar May 05 '24 17:05 Flyingmana

@Flyingmana here:

https://github.com/OpenMage/magento-lts/pull/4078

https://github.com/OpenMage/magento-lts/pull/4079

eneiasramos avatar Jul 03 '24 23:07 eneiasramos

replaced by https://github.com/OpenMage/magento-lts/pull/4079 and https://github.com/OpenMage/magento-lts/pull/4078

fballiano avatar Jul 06 '24 09:07 fballiano