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 product review validation's notInRangeMessage #14584

Conversation

diimpp
Copy link
Member

@diimpp diimpp commented Nov 25, 2022

Q A
Branch? 1.13
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? yes
Related tickets partially #14576
License MIT

Continuation of #14576 based on 1.13 due deprecation and changes introduced in 1.12

--- range: Review rating must be an integer in the range 1-5.
+++ not_in_range: Review rating must be between {{ min }} and {{ max }}.

Range constraints doesn't validate for integer type, so I've removed mention of this and was forced to remove translated strings from other languages.

Validates that a given number or DateTime object is between some minimum and maximum.

@probot-autolabeler probot-autolabeler bot added API APIs related issues and PRs. Maintenance CI configurations, READMEs, releases, etc. labels Nov 25, 2022
@diimpp diimpp force-pushed the bugfix/1.13_constraint_range_not_in_range_message branch 2 times, most recently from 500fdc8 to 6bed76a Compare November 25, 2022 21:32
@diimpp diimpp marked this pull request as ready for review November 25, 2022 21:57
@diimpp diimpp requested a review from a team as a code owner November 25, 2022 21:57
@@ -100,8 +100,6 @@ sylius:
review:
author:
not_blank: Bitte geben Sie Ihre E-Mail-Adresse ein.
rating:
range: Bewertung muss eine Ganzzahl im Bereich 1-5 sein.
Copy link
Contributor

@Nek- Nek- Nov 25, 2022

Choose a reason for hiding this comment

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

I guess it should be removed from all locales (idk how to forward the change to crowdin)

Copy link
Member Author

Choose a reason for hiding this comment

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

it's already removed from all locales, just a few of them had that translation defined.

Copy link
Member Author

Choose a reason for hiding this comment

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

$ cd src/Sylius/Bundle/CoreBundle/Resources/translations 
$ ag -i range
validators.en.yml
117:            not_in_range: Review rating must be between {{ min }} and {{ max }}.

@diimpp diimpp requested a review from Nek- November 26, 2022 00:44
TheMilek added a commit that referenced this pull request Jan 31, 2023
…(diimpp, GSadee)

This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.11                  |
| Bug fix?        | yes                                                       |
| New feature?    | no                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | yes  |
| Related tickets | fixes #13883                       |
| License         | MIT                                                          |

**Issue**
Symfony validation constraint [`Range`](https://symfony.com/doc/4.4/reference/constraints/Range.html#notinrangemessage) instroduced new behavior since 4.4 release -- if both `min` and `max` options are defined, then `notInRangeMessage` will be shown and `minMessage`/`maxMessage` will be disregarded.

<details><summary>Example</summary>

If you will try to generate coupons for promotion with code length larger than 40, then you will see symfony standard message `notInRangeMessage: This value should be between {{ min }} and {{ max }}.` instead of sylius `maxMessage: Coupon code must not be longer than {{ limit }} characters.`
![image](https://user-images.githubusercontent.com/870747/203878039-2d6ac8c3-130c-4758-a7ae-bd638817faf7.png)


</details>

#### Case 1

https://github.com/Sylius/Sylius/blob/9506c80f2080b34b89f51b54e7e8f3490c8b7d36/src/Sylius/Bundle/PromotionBundle/Resources/config/validation/PromotionCouponGeneratorInstruction.xml#L33-L37

- [x] Remove minMessage, maxMessage and their translations
- [x] Introduce notInRangeMessage and new translation
- [x] Cover case with behat scenario 

#### Case 2
https://github.com/Sylius/Sylius/blob/9506c80f2080b34b89f51b54e7e8f3490c8b7d36/src/Sylius/Bundle/PromotionBundle/Form/Type/Action/UnitPercentageDiscountConfigurationType.php#L35-L41

- [x] Remove minMessage, maxMessage usage; Their translations were already removed.
- [x] Introduce notInRangeMessage; Translation already exists as it's shared between order/item percentage discount
- [x] Cover case with behat scenario

#### Case 3
https://github.com/Sylius/Sylius/blob/9506c80f2080b34b89f51b54e7e8f3490c8b7d36/src/Sylius/Bundle/ApiBundle/Resources/config/validation/AddProductReview.xml#L23-L28

- [x] Remove minMessage, maxMessage
- [x] Rename translation key `range` to `not_in_range`
- [x] Move to separate #14584 due deprecation.

**Questions**
1. Does removal of `sylius.promotion_coupon_generator_instruction.code_length.min` and `...max` messages constitute a deprecation entry? Because those translation strings were inactive (effectively deprecated by symfony upgrade) since project was upgraded to symfony 4.4 and even if somebody has custom translation over there, it has no effect whatsoever. 
2. Please advise on adding/removal of translation strings, do I need to do anything else? I do recall some translation service was in use.


Commits
-------

f1ae3df Set correct notInRangeMessage for coupon generation validation
f55babd Set correct notInRangeMessage for unit percentage discount promotion action
7d88a38 [Behat] Add minor improvements to range validations fixes
63e8b69 [Promotion] Revert removing min and max validation messages for code length
@coldic3 coldic3 self-assigned this Mar 9, 2023
Copy link
Contributor

@coldic3 coldic3 left a comment

Choose a reason for hiding this comment

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

Hey @diimpp, could you keep sylius.review.rating.range instead of defining the new sylius.review.rating.not_in_range? If so, the PR is mergeable IMO. Thanks!

@diimpp
Copy link
Member Author

diimpp commented Mar 9, 2023

Hey @diimpp, could you keep sylius.review.rating.range instead of defining the new sylius.review.rating.not_in_range? If so, the PR is mergeable IMO. Thanks!

Hi, but correct string is not_in_range, I can leave range as is and introduce new one not_in_range as similarly was done in parent ticket #14576

@coldic3
Copy link
Contributor

coldic3 commented Mar 9, 2023

@diimpp Yeah, good idea. Would be great to leave that one and introduce a new one.

@jakubtobiasz jakubtobiasz force-pushed the bugfix/1.13_constraint_range_not_in_range_message branch 2 times, most recently from 0d3abb7 to 8c682d1 Compare April 28, 2023 09:25
jakubtobiasz
jakubtobiasz previously approved these changes Apr 28, 2023
Copy link
Member

@jakubtobiasz jakubtobiasz left a comment

Choose a reason for hiding this comment

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

Hi!
Thanks for your work. I've restored the old key to behave BC compatibility, in case someone is using it elsewhere :).

@jakubtobiasz jakubtobiasz force-pushed the bugfix/1.13_constraint_range_not_in_range_message branch from 8c682d1 to 4bada6d Compare May 1, 2023 10:24
@jakubtobiasz jakubtobiasz merged commit 21a2174 into Sylius:1.13 May 2, 2023
23 checks passed
@jakubtobiasz
Copy link
Member

Thank you, @diimpp!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API APIs related issues and PRs. Maintenance CI configurations, READMEs, releases, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants