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

Fix config backend model PDF file name extension #24153

Merged
merged 4 commits into from
Sep 26, 2019

Conversation

Vinai
Copy link
Contributor

@Vinai Vinai commented Aug 16, 2019

Description (*)

The PDF system config file backend model does not include the file name ending pdf in the list of allowed extensions.
Instead, it allows the extensions ['tif', 'tiff', 'png', 'jpg', 'jpe', 'jpeg'], which are not relevant for PDF files.

This PR adds pdf to the list of allowed extensions without removing the existing wrong extensions. This way it's a backward compatible change, and it makes the backend model usable for PDFs.

It also adds a new backend model \Magento\Config\Model\Config\Backend\Image\Pdf as a replacement that only returns the allowed file name extension pdf.

I added a @deprecated annotation to the existing backend model with an explanation and a @see annotation to point to the new PDF backend model.

Manual testing scenarios (*)

Referencing the backend model in a system.xml file, e.g

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="foo" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="200">
            <label>Foo</label>
            <tab>general</tab>
            <resource>Magento_Customer::config_customer</resource>
            <group id="bar" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="10">
                <label>Example</label>
                <field id="baz" type="file" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="10">
                    <label>PDF Upload</label>
                    <backend_model>Magento\Config\Model\Config\Backend\Image\Pdf</backend_model>
                    <upload_dir scope_info="1">foo/bar</upload_dir>
                    <base_url type="media" scope_info="1">foo/bar</base_url>
                </field>
            </group>
        </section>
    </system>
</config>

Then upload a file with a .pdf extension. It will be rejected by the server side validation in \Magento\Config\Model\Config\Backend\File::beforeSave

Questions or comments

I'm not sure what the best way is to get this PR merged as quickly as possible.
If the deprecation of the @api class and addition of a new @api class prevent it from being merged, I would suggest to remove those annotations and just merge the file changes, and then add the annotations in a new PR that can be merged in the next major release.
Open to other suggestions if there is a better approach.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Aug 16, 2019

Hi @Vinai. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

In case you'd like to rerun tests use the following comments:

  • @magento run all tests - run all tests
  • @magento run { check name } - run a single test job (check name example: Static Tests build)

For more details, please, review the Magento Contributor Guide documentation.

@ghost ghost assigned sidolov Aug 16, 2019
@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-5648 has been created to process this Pull Request
✳️ @sidolov, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@engcom-Delta
Copy link
Contributor

✔️ QA passed

@engcom-Foxtrot
Copy link
Contributor

@magento run all tests

@engcom-Foxtrot engcom-Foxtrot self-assigned this Aug 22, 2019
@Vinai
Copy link
Contributor Author

Vinai commented Aug 26, 2019

Thanks for catching the namespace bug. Regarding the @inheritdoc annotation, according to https://devdocs.magento.com/guides/v2.3/coding-standards/docblock-standard-general.html#inheritdoc it should not be used.
I guess it's okay if it's still required to get the tests to pass, but I hope it won't be necessary anymore soon.

@Vinai
Copy link
Contributor Author

Vinai commented Sep 17, 2019

@sidolov Is there anything I can do to help move this PR forward?

@sidolov sidolov added the Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests label Sep 17, 2019
@m2-assistant
Copy link

m2-assistant bot commented Sep 26, 2019

Hi @Vinai, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants