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
Restore X value in contact boolean fields #10716
Restore X value in contact boolean fields #10716
Conversation
Tried it a bit, seem to work perfect in the web GUI, but over the REST API I cannot set it to X. I have tried setting a null-var but it does not work. So for exampe this works to set Yes: This works to set No But this does not work to set X: Would be great if we can have this fixed as well |
@jensolsson Thank you for feedback. Setting |
Problem is that in that case all values I do not explicity set are reset to null. For example if I completely leave out for example "title" then it would set it to null on the contact even though the contact already have a title as CEO for example. So this imposes a great problem when having multiple data sources. |
This case actually works fine for me.
Contact created, id: 489 Edit contact with PATCH method:
After update the contact title is persisted. |
We always create new contacts with Post to /api/contacts/new and it has always worked. It just changes the fields we send and it updates the existing contact if it existe. The overhead of first searching for the contact and using its id would be alot i think even though it would be possible. But maybe it worked the same in <4.0.0. I have never had a need to reset a yesno switch via the api before. |
Here is another one referencing this complicated sequence https://forum.mautic.org/t/mautic-api-editing-contact-by-email/16997 |
Updating contacts using the create method doesn't really seem correct to me, it works because of contact merging functionality. In my opinion, the changes you suggest should be the subject of another PR. Let's focus here on fixing the boolean fields, which I think is more critical. |
Totally agree with you this is off topic. |
Codecov Report
@@ Coverage Diff @@
## 4.1 #10716 +/- ##
============================================
+ Coverage 44.76% 45.03% +0.26%
- Complexity 34814 34815 +1
============================================
Files 2080 2080
Lines 116716 116737 +21
============================================
+ Hits 52246 52568 +322
+ Misses 64470 64169 -301
|
This is interesting. We must ensure that the API Library test that was failing before and why the changes were originally made are passing with this change. I wanted to run GitHub Actions on this PR but it failed on outdated Composer package. I prepared a fix for that but it needs reviewers. is blocking this PR until merged. |
So the API Library tests are passing on
So that needs to be addressed before we can merge this PR. |
Line app/bundles/ChannelBundle/Controller/Api/MessageApiController.php ------ ------------------------------------------------------------------- 32 Property Mautic\ChannelBundle\Controller\Api\MessageApiController::$model (Mautic\ChannelBundle\Model\MessageModel) does not accept Mautic\CoreBundle\Model\AbstractCommonModel.
"file":"\/var\/www\/html\/mautic\/app\/bundles\/ChannelBundle\/Controller\/Api\/MessageApiController.php","line":54 I cannot figure out why the condition for PATCH was there in the first place. It's causing only troubles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the API error in the original PR that this one reverts. The API Library error on SummaryModel is not related to this PR and is fixed in #10708
I can confirm the regression bug and this PR fixes that. The problem is in Symfony forms themselves. They take false
as null
for reasons I don't comprehend. So we have to go back to 0
and 1
in order to support the empty|null
option for boolean custom fields.
I approved it prematurely. The tests fail on normal patch endpoint:
I'm editing marketing message with
similar to the one in the test: https://github.com/mautic/api-library/blob/main/tests/Api/MessagesTest.php#L26-L42 But it just works... I cannot understand why it's failing. I cannot reproduce it. It should be asserting true but it's asserting false for some reason. I'll have to sleep on it. (or anyone else see the problem?) |
@escopecz the failing test payload is
And then this conditional is is setting
|
@patrykgruszka that's what I was missing. Thanks for guidance! I prepared the fix with several tests in c2b3c85 I somehow lost ability to push to your fork directly. Could you please do this:
|
…hod, fixing the controller
Sure, done. There is a problem with one test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have different error level setting on my local that it did not show up the problem. Thanks! I managed to push to your branch again. Everything is green including the API Library tests (as mentioned above, the last failing test is not related and fixed in another PR)
@patrykgruszka thanks for this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @patrykgruszka and for fixing this issue!
Tested in the UI and the API as instructed (thanks for the very clear instructions with the JSON!) and all cases are acting as expected:
Via the API:
LGTM! 🚀
@all-contributors please add @jensolsson for userTesting |
I've put up a pull request to add @jensolsson! 🎉 |
* Update language string (#10684) The button that i updated is for saving changes made in the "Edit code" window and should thus say "Save", not "Edit". * Fixes 500 error in forms when render style is deactivated against 4.1 (#10697) * Fixes issue #10453 * Adding functional test covering the bug #10453 Co-authored-by: Rolando <rpayanm@gmail.com> * Fixing issues when using PHPSTAN with more processes (#10696) * Bumping to version 4.1.1 * Remove reference to mautibox (#10681) * Fix lock wait deleting unused ips (#10710) * Deleted unused IPs in batches and some improvements. * Added return type declaration to command methods and some improvements. * Removed dump() * Created separate methods for get and delete unused ips. * Consumed repo methods in model. * Updated command to use model methods. * Added test case. * Fix static analysis * Fix contact batch api for single id value (#10700) Co-authored-by: John Linhart <admin@escope.cz> * fix(LeadTimelineEvent): keys do not match the func args, strips keys (#10663) Fix error when using PHP 8: {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): array_merge() does not accept unknown named parameters} Not sure if this is the most elegant way to address the issue but this bug has broken the site functionality. * User update role api (#10668) * Allow user to update role via API * Update user's role using API: test cases * Update user's role using API: added more test cases * Fix test cases and add more test case * Added AbstractMauticTestCase::loginUser() method that allows login user in non-restricted areas * Fix failing tests Co-authored-by: fedys <miroslav.fedeles@gmail.com> Co-authored-by: John Linhart <admin@escope.cz> * Fix send unpublished SMS (#10577) * Fix send unpublished SMS * Fix send unpublished SMS for broadcast command * Add CampaignSendSubscriberTest * Add testSendSmsNotPublished test * Minor change to tests * Fixing types * Automatic cs fix Co-authored-by: John Linhart <admin@escope.cz> * Fix group by If you use count columns for assets download (#10693) * Fix group by If you use count columns * Add unit tests * Fix unit tests * Remove define from tests * Fix unit tests * Fix unit tests * Fix unit tests Co-authored-by: John Linhart <admin@escope.cz> * Update grapesjs-custom.css (#10728) Removing the background color f0f0f0 from gjs-field-radio class to improve the color constrast between radio's background and radio's options and returning the class parameters to the default of the original editor. Co-authored-by: Ruth Cheesley <ruth.cheesley@acquia.com> * Update stale.yml (#10746) Apply Stalebot only to issues and not PRs Co-authored-by: John Linhart <admin@escope.cz> * Fixed variable name (#10753) Co-authored-by: Ruth Cheesley <ruth.cheesley@acquia.com> Co-authored-by: Joey Keller <jos0405@gmail.com> * Change field definition for column_value to longtext instead of varchar (#10778) * Change field definition for column_value to longtext instead of varchar 255 * Update app/migrations/Version20200729170800.php Co-authored-by: John Linhart <admin@escope.cz> * I suggested bad namespace path during code review. Fixing it here Co-authored-by: Don Gilbert <don@dongilbert.net> * Correct bug no forms in the select contact source campaign when the forms have identical names (#10717) * Correct name form Campaign Contact Source * Refactoring and add test * Finishing up the test * Fixing the bug discovered by the test * CS fix Co-authored-by: John Linhart <admin@escope.cz> Co-authored-by: Ruth Cheesley <ruth.cheesley@acquia.com> * Restore X value in contact boolean fields (#10716) * Fix empty value in contact boolean fields * Fix configuration page save * Fix controller functional tests * Always retype the isEnabled param to int. Even for PATCH * Fixing phpstan issue Line app/bundles/ChannelBundle/Controller/Api/MessageApiController.php ------ ------------------------------------------------------------------- 32 Property Mautic\ChannelBundle\Controller\Api\MessageApiController::$model (Mautic\ChannelBundle\Model\MessageModel) does not accept Mautic\CoreBundle\Model\AbstractCommonModel. * Fixing PHP Notice - Undefined index: email "file":"\/var\/www\/html\/mautic\/app\/bundles\/ChannelBundle\/Controller\/Api\/MessageApiController.php","line":54 I cannot figure out why the condition for PATCH was there in the first place. It's causing only troubles. * Adding functional API tests covering the problematic endpoint and method, fixing the controller * Fix csfixer issue * Adding missing description to payloads for assertion Co-authored-by: John Linhart <admin@escope.cz> Co-authored-by: Ruth Cheesley <ruth.cheesley@acquia.com> * Add missing information (#10656) * Add missing information * Missing commas 😊 * Fix for pushing to integrations in campaign actions (#10674) * Fix for #10517 Some integrations such as Hubspot have an `'encode_parameters' => 'json'` setting, which triggers the parameters being sent in `POST` / `PUT` / `PATCH` requests to be `json_encode`-d: https://github.com/mautic/mautic/blob/5975231722cfde8bdad783b373c70ad20333db37/app/bundles/PluginBundle/Integration/AbstractIntegration.php#L760 That causes a problem when the result is passed to Guzzle's `request` method under key `\GuzzleHttp\RequestOptions::FORM_PARAMS`, because the payload is expected to be an array: https://github.com/mautic/mautic/blob/5975231722cfde8bdad783b373c70ad20333db37/app/bundles/PluginBundle/Integration/AbstractIntegration.php#L829 as per the documentation: https://docs.guzzlephp.org/en/stable/request-options.html#form-params The above RP addresses this by passing the payload under `\GuzzleHttp\RequestOptions::BODY` instead, **if** the payload is a string, rather than an array. Tested and working with HubSpot. * Adding test to the payload key fix * Creating Client in another method so it could be mocked Plus some code style improvements * CS Fixer * STAN fixes * Removing whitespace Co-authored-by: John Linhart <admin@escope.cz> Co-authored-by: Ruth Cheesley <ruth.cheesley@acquia.com> * Bump to 4.1.2 Co-authored-by: Kathrin Schmid <96054002+kathrin-schmid@users.noreply.github.com> Co-authored-by: John Linhart <admin@escope.cz> Co-authored-by: Rolando <rpayanm@gmail.com> Co-authored-by: Tejas Navghane <ts.navghane@gmail.com> Co-authored-by: Rahul Dhande <68939488+rahuld-dev@users.noreply.github.com> Co-authored-by: Anthony Bailey <65302481+abailey-dev@users.noreply.github.com> Co-authored-by: fedys <miroslav.fedeles@gmail.com> Co-authored-by: Zdeno Kuzmany <zdeno@kuzmany.biz> Co-authored-by: Eloi Marques da Silva <eloimarquessilva@gmail.com> Co-authored-by: mollux <mattias.michaux@gmail.com> Co-authored-by: Joey Keller <jos0405@gmail.com> Co-authored-by: Don Gilbert <don@dongilbert.net> Co-authored-by: Tomasz Kowalczyk <39382654+tomekkowalczyk@users.noreply.github.com> Co-authored-by: Patryk Gruszka <patryk.gruszka@comarch.pl> Co-authored-by: Tony Bogdanov <tonybogdanov@gmail.com>
Description:
This PR reverts changes from #9931 that caused issues with contact boolean fields.
YesNoButtonGroupType
actually uses the SymfonyChoiceType
and not theCheckboxType
as assumed in #9931, so the1
0
options should be correct.After applying this PR the boolean fields in the contact edit page should have 3 options again:
Before applying this PR:
I have checked the failing test
Mautic\Tests\Api\MessagesTest::testBatchEndpoints
from Mautic API repo, and it works fine after applying this PR. I couldn't replicate this issue from #9931.Steps to test this PR:
X
Yes
No
. Test changing the state.X
Yes
No
. Test changing the state.#9931 Regression tests
4. Browse the UI and toggle the Yes/No buttons in various forms and on the contact edit page. Changing the state, saving, and editing should repopulate the correct state.
5. API functional tests should pass (the 5 tests that failed always fail on my local)
6. Test the Configuration can be saved and manipulated
7. Create a batch of messages via the API
POST /api/messages/batch/new
(change channelId to be the ID of an Email and SMS that exists in your Mautic)
Then try to PATCH by switching the isEnabled of each channel and adding the message ID:
PATCH /api/messages/batch/edit
Then try PUT as well
PUT /api/messages/batch/edit
Finally, try using 0/1 instead of true/false.