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

IBX-6856: Added mime types limitation for ezimage field type #300

Merged

Conversation

ciastektk
Copy link
Contributor

@ciastektk ciastektk commented Dec 1, 2023

Question Answer
JIRA issue IBX-6856
Type feature
Target Ibexa version v4.6
BC breaks no

Requires:
ibexa/admin-ui#1021
ibexa/content-forms#55
https://github.com/ibexa/image-editor/pull/80

This PR adds mimeTypes field setting to store which mime types are allowed for Image Field type. If empty array then all image mime types are allowed.

There is also added ibexa.field_type.ezimage.mime_types parameter with predefined mime type list that will be displayed in Image Field type definition.

Screen Shot 2023-12-04 at 13 04 24

Checklist:

  • Provided PR description.
  • Tested the solution manually.
  • Provided automated test coverage.
  • Checked that target branch is set correctly (main for features, the oldest supported for bugs).
  • Ran PHP CS Fixer for new PHP code (use $ composer fix-cs).
  • Asked for a review (ping @ibexa/engineering).

@@ -36,14 +36,29 @@ class Type extends FieldType implements TranslationContainerInterface
],
];

/** @var array<string, array<array<mixed>|scalar>> */
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to properly define array shape here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed: 2e03387

src/lib/FieldType/Image/Type.php Outdated Show resolved Hide resolved
@webhdx webhdx requested a review from a team December 4, 2023 10:36
@@ -98,7 +99,7 @@ abstract public function validateConstraints($constraints);
*
* @return bool
*/
abstract public function validate(Value $value);
abstract public function validate(Value $value, ?FieldDefinition $fieldDefinition = null);
Copy link
Member

@alongosz alongosz Dec 4, 2023

Choose a reason for hiding this comment

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

Tip

This is not an internal class, but it hasn't been documented as an SPI either, so I would just add a note in the upgrade/release notes that this method got an extra parameter (If it were an SPI it would be a breaking change).

{
// silence `getimagesize` error as extension-wise valid image files might produce it anyway
// note that file extension checking is done using other validation which should be called before this one
if (!@getimagesize($filePath)) {
if (!$imageData = @getimagesize($filePath)) {
Copy link
Member

Choose a reason for hiding this comment

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

what kind / types of values causes !$imageData to evaluate to true or false? Can we be always more strict? As a reminder !'0' evaluates to true and yet it is some sort of data ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!$imageData = @getimagesize($filePath)) {
$imageData = @getimagesize($filePath);
if ($imageData !== false) {

Negation of variable assignment inside of condition can be confusing and less readable expression. It is better to avoid it in a first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

]
);
}

/**
* @return array<string>
Copy link
Member

Choose a reason for hiding this comment

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

either I'm reading the method wrong, or this is not correct. I wonder why we don't have anything on this from PHPStan. In pure playground environment it reports here an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

{
// silence `getimagesize` error as extension-wise valid image files might produce it anyway
// note that file extension checking is done using other validation which should be called before this one
if (!@getimagesize($filePath)) {
if (!$imageData = @getimagesize($filePath)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!$imageData = @getimagesize($filePath)) {
$imageData = @getimagesize($filePath);
if ($imageData !== false) {

Negation of variable assignment inside of condition can be confusing and less readable expression. It is better to avoid it in a first place.

@ciastektk ciastektk force-pushed the ibx-6856-added-mime-types-limitation-for-ezimage-field-type branch from 32ecebe to c44b948 Compare December 5, 2023 10:15
Base automatically changed from ibx-6937-changed-max-file-size-value-to-float to main December 6, 2023 08:41
@ciastektk ciastektk force-pushed the ibx-6856-added-mime-types-limitation-for-ezimage-field-type branch from c44b948 to 6cd0d98 Compare December 6, 2023 09:01
Copy link

sonarcloud bot commented Dec 8, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

No Coverage information No Coverage information
0.6% 0.6% Duplication

@webhdx webhdx merged commit 3fd56c6 into main Dec 14, 2023
22 checks passed
@webhdx webhdx deleted the ibx-6856-added-mime-types-limitation-for-ezimage-field-type branch December 14, 2023 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature request Ready for QA
Projects
None yet
8 participants