Problem/Motivation

As part of #2940383: [META] Unify file upload logic of REST and JSON:API we want to refactor common code. As a smaller step to that goal, we can refactor \Drupal\file\Plugin\rest\resource\FileUploadResource to use the existing \Drupal\file\Upload\FileUploadHandler::handleFileUpload() and thereby reduce the size of the larger refactoring.

Steps to reproduce

Proposed resolution

Refactor FileUploadResource to use FileUploadHandler

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3401734

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kim.pepper created an issue. See original summary.

kim.pepper’s picture

Title: Refactor FileUploadResource to use FileUploadHandler » [PP-1] Refactor FileUploadResource to use FileUploadHandler
Status: Active » Postponed

Found a mismatch in behaviour with the filename field on the File entity not being updated when we do a rename.

I think this is now blocked on #3402981: Filename property is not updated when a duplicate file is renamed In REST and JSON API file uploads

kim.pepper’s picture

larowlan’s picture

Title: [PP-1] Refactor FileUploadResource to use FileUploadHandler » Refactor FileUploadResource to use FileUploadHandler

Blocker is in

kim.pepper’s picture

There is a test failure due to a behaviour change. I'm scratching my head to work out why.

Before: example.php gets renamed:
example.php => example.php_.txt

After: example.php gets rejected because the .php extension isn't in the allow extensions list.

kim.pepper’s picture

Status: Needs work » Needs review

Many thanks to @larowlan for helping resolve the file extensions issues. 🙌🏻🥳

This is ready for reviews now.

kim.pepper’s picture

Priority: Normal » Critical

Changing this to critical as it is a part of #2940383: [META] Unify file upload logic of REST and JSON:API which is critical.

alexpott’s picture

Status: Needs review » Needs work

Added a review to the MR... this is looking lovely.

pradhumanjain2311 made their first commit to this issue’s fork.

kim.pepper’s picture

Status: Needs work » Needs review

@alexpott are you happy if we look into your concerns in #3403253: Simplify how 'allow all extensions' file upload validation works?

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

Re #11 yeah - I don't think your code is changing any of the current behaviour ... it's just whenever I see code allowing all extensions I get very security nervous.

kim.pepper’s picture

longwave’s picture

Status: Reviewed & tested by the community » Needs work

This looks great, unifying all this is definitely the way to go, but the patch does not apply to 10.3.x/10.4.x so we will need a separate MR.

I'm also in two minds about removing the deprecation in 11.x at this stage. https://www.drupal.org/project/file_upload_options does extend this plugin in contrib but only has a beta release and 123 users.

If we do remove the deprecation in 11.x then we will need an 11.x MR with the deprecations removed. Otherwise, the deprecations need updating to 12.x

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

I think since it is constructor deprecations and not actually covered by our BC promise we should deprecate in 10.x and remove in 11.x. Contrib does not need to override the constructor - they can do what they need in the create method.

Removed deprecations from the 11.x branch and created an 10.4.x branch resolving the conflict.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Couple of deprecations still in the 11.x branch - other than that looks good to me

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

removed the deprecated functions from 11.x branch. nice catch @larowlan

longwave’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed f757b3d and pushed to 11.x. Thanks!

Committed and pushed 8f38f5d839 to 10.4.x and 48c58073ee to 10.3.x. Thanks!

longwave’s picture

  • longwave committed 48c58073 on 10.3.x
    Issue #3401734 by kim.pepper, alexpott, larowlan, pradhumanjain2311:...

  • longwave committed 8f38f5d8 on 10.4.x
    Issue #3401734 by kim.pepper, alexpott, larowlan, pradhumanjain2311:...

  • longwave committed f757b3d3 on 11.x
    Issue #3401734 by kim.pepper, alexpott, larowlan, pradhumanjain2311:...

  • longwave committed f757b3d3 on 11.0.x
    Issue #3401734 by kim.pepper, alexpott, larowlan, pradhumanjain2311:...
kim.pepper’s picture

kim.pepper’s picture

We left in the method InputStreamUploadedFile::supportsMoveUploadedFile() from an approach that we ditched in favour of the InputStreamUploadedFile::validate() approach. Created #3446962: Remove incorrectly added InputStreamUploadedFile::supportsMoveUploadedFile() to clean this up.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.