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

WIP: photo conversion (Supercedes #404) #412

Closed
wants to merge 3 commits into from

Conversation

ssempervirens
Copy link
Member

@ssempervirens ssempervirens commented Mar 24, 2018

Status

In progress, still need to resolve tests and write unit tests before merge

Description of Changes

Fixes #369. Supersedes PR #404

Changes proposed in this pull request:

  • Converts tiff and psd file submissions to jpegs

Notes for Deployment

Screenshots (if appropriate)

Tests and linting

[x] I have rebased my changes on current develop

[] pytests pass in the development environment on my local machine

[] flake8 checks pass

@ssempervirens ssempervirens changed the title supercedes #404, still WIP and need to write tests WIP: photo conversion (Supercedes #404) Mar 24, 2018
@@ -95,6 +96,18 @@ def allowed_file(filename):
filename.rsplit('.', 1)[1].lower() in current_app.config['ALLOWED_EXTENSIONS']


def requires_conversion(filename):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be dandy (I'm bringing this word back) to have a unit test for requires_conversion. It could be modeled off test_user_can_submit_allowed_file below - the asserts would verify that the correct result is returned by the function for files that do and do not require conversion.

@@ -450,6 +451,8 @@ def upload(department_id):
file_to_upload = request.files['file']
if not allowed_file(file_to_upload.filename):
return jsonify(error="File type not allowed!"), 415
if requires_conversion(file_to_upload.filename):
convert_image()
Copy link
Member

@redshiftzero redshiftzero Apr 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the image is getting converted and saved on the filesystem but then we don't use the result and instead continue to use the image data stored in file_to_upload.filename (also in convert_image we actually remove the contents of file_to_upload.filename). I think we'll want to return the filename in convert_image and then use that image for the remainder of the code in upload.

filename.split('.', 1)[1].lower() in current_app.config['REQUIRES_CONV']


def convert_image(file_to_upload):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test here would also be 💯 - it could assert:

  1. The original image is deleted
  2. The modified image is created
  3. The name or path of the modified file is returned (see comment above)

@ssempervirens
Copy link
Member Author

Hey @redshiftzero I am working on this, and I am confused about how to write a unit test for this without mock s3 bucket capabilities. Do you have any thoughts?

@raq929
Copy link

raq929 commented Jul 1, 2018 via email

@raq929
Copy link

raq929 commented Jul 1, 2018 via email

@ssempervirens
Copy link
Member Author

@raq929 sweet, totally missed that, sounds great! will play with this later this week in that case. :)



def convert_image(file_to_upload):
changeimage = Image.open(file_to_upload.filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're calling Image.open() on untrusted content here, can you also hoist the decompression-bomb-safety warning into an error as documented in PIL's docs? AIUI we've been mostly free of risk-to-the-server for the files we're uploading since we were only reading headers out of them before, but now we're doing parsing and things that risk actual attack.

@redshiftzero
Copy link
Member

Closing in favor of #691

@r4v5 r4v5 deleted the photoconversion branch July 19, 2020 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow upload of additional image formats
4 participants