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

feat(utility/fileupload): file_validate_image_resolution #1342

Merged

Conversation

aurelianzaha
Copy link
Contributor

make it possible to validate the image resolution

file size and file extension validation is already in place

Copy link
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

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

Makes sense, can simplify a bit with the ?? operator?

@aurelianzaha aurelianzaha requested a review from klausi May 2, 2023 14:05
@klausi
Copy link
Contributor

klausi commented May 2, 2023

Hm, but will this change be enough? getUploadValidators() is called only once, then the $validator array is passed to prepareFilename(), but it is never looped over?

Can you add a test case to UploadFileServiceTest?

We copied the code from Drupal core FileItem, how does an image file item handle this? I guess it is done in ImageWidget, that's why it is missing.

@klausi
Copy link
Contributor

klausi commented May 2, 2023

Another problem is that you cannot use file_validate_image_resolution() fully because it invokes the drupal message system when changing the scale of an image. That is not ideal, as it starts a user session that you don't need.

So probably you will need a copy of file_validate_image_resolution() as method in our file upload service.

@aurelianzaha
Copy link
Contributor Author

aurelianzaha commented May 4, 2023

Hm, but will this change be enough? getUploadValidators() is called only once, then the $validator array is passed to prepareFilename(), but it is never looped over?

Can you add a test case to UploadFileServiceTest?

We copied the code from Drupal core FileItem, how does an image file item handle this? I guess it is done in ImageWidget, that's why it is missing.

@klausi yes, that is enough, the $validators array is used here
https://github.com/drupal-graphql/graphql/blob/8.x-4.x/src/GraphQL/Utility/FileUpload.php#L261
this is where the loop happens

@aurelianzaha
Copy link
Contributor Author

@klausi I made a copy of file_validate_image_resolution do we still need the tests ?

Copy link
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

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

Ah great, overlooked file_validate().

Yes, please add a test!

@joaogarin joaogarin requested a review from klausi May 9, 2023 07:10
Copy link
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

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

Thanks, approach makes sense. I see some minor issues and please add a test case for minimum resolution settings as well that you get out an error message.

@aurelianzaha aurelianzaha requested a review from klausi May 17, 2023 08:39
Copy link
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@klausi klausi merged commit bf9dea3 into drupal-graphql:8.x-4.x May 17, 2023
klausi pushed a commit to klausi/graphql that referenced this pull request Sep 21, 2023
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.

3 participants