Repository navigation
Conversation
…ert API CustomAlerts.addAlert and CustomAlerts.editAlert declared additionalEmails and phoneNumbers without a type and without a default, so the API proxy rejected any request that omitted them (as standard form encoders do for empty arrays) with "Please specify a value". Type them as nullable arrays so a missing, empty or null value means "no entries", and ignore empty/null entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
….0.6 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Auto-fix agent: fixed checks broken by this PR (ci / release-date / Release date). ci / release-date failed: the PR bumped plugin.json to 6.0.6 with a new undated 6.0.6 changelog entry while 6.0.5 (translations) is also undated and not yet tagged/released, so the weekly release would skip 6.0.5. Changed:
|
snake14
left a comment
There was a problem hiding this comment.
Missing, null and empty additionalEmails / phoneNumbers are now accepted by both addAlert and editAlert. A couple of things to check:
Medium
- A non-array value such as
additionalEmails=a@example.com(no[]) now gets a success response, but the alert is saved without that recipient, and oneditAlertthe stored list is erased. Before, the request failed, so the client knew. Silently dropping a recipient is worse than that error, so could a value that is present but not an array be rejected with an error naming the parameter, with a test case for it?Low
- The
$phoneNumber === ''check infilterPhoneNumbers()can't change the result, sincein_array('', $availablePhoneNumbers)is already false on PHP 8, so it can be dropped.
…ditAlert Auto-sanitized API parameters fall back to null when the request holds a value of the wrong type, so additionalEmails=a@example.com was answered with success while the recipient was dropped (and erased on editAlert). Such a value is now rejected with HTTP 400 naming the parameter, covered by new integration tests for both methods and both parameters. Also drop the empty-string check in filterPhoneNumbers(), which could not change the result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Auto-fix agent, replying to @snake14:
Both points fixed. Plugin API parameters are auto-sanitized, so a value of the wrong type reached the method as null and was saved as no entries; addAlert and editAlert now reject a present non-array additionalEmails or phoneNumbers with HTTP 400 (General_InvalidValueForParameter naming the parameter), while missing, null and empty values are still accepted. New integration tests cover both methods and both parameters and check that no alert is created and the edited alert keeps its stored recipients. The redundant $phoneNumber === '' check in filterPhoneNumbers() is removed. |
|
Auto-fix agent: pushed edcbf20 for the review feedback. addAlert and editAlert now reject a non-array additionalEmails or phoneNumbers with HTTP 400 instead of silently saving no recipients (auto-sanitized parameters turned such values into null). Changed:
|
snake14
left a comment
There was a problem hiding this comment.
Missing and empty lists are accepted, and a non-array additionalEmails or phoneNumbers is now rejected with HTTP 400, including inside a bulk request. One item to check:
Low
- The two new
shouldFail_IfOptionalListFieldIsNotAnArraytests catch\Exceptionand only check the message, so a plainExceptionwould pass too. AssertingBadRequestExceptionand code 400, liketest_addAlert_ShouldFail_IfEmptyNamedoes, would pin the HTTP 400 the changelog promises.
…ests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…irect API tests Request::processRequest() replaces the exception by a plain Exception without code in tests, so the end-to-end tests keep checking the message and stored state, while new direct API calls assert the exception class and code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Auto-fix agent, replying to @snake14:
Added direct API tests for addAlert and editAlert that send the non-array value in the request and expect BadRequestException with code 400 and the General_InvalidValueForParameter message, like test_addAlert_ShouldFail_IfEmptyName. The two existing end-to-end tests still go through Request::processRequest(), which in tests replaces the exception by a plain Exception without code, so they keep checking the message and that nothing was saved; a comment now explains this. |
|
Auto-fix agent: pushed cb7efa1 for the review feedback. Tests only: new direct API tests pin BadRequestException and HTTP 400 when additionalEmails or phoneNumbers is sent as a non-array to addAlert or editAlert. Changed:
|
lincolnops
left a comment
There was a problem hiding this comment.
Merged 6.x-dev and resolved the CHANGELOG.md conflict; the pull request's own changes are as approved before, so the approval stands.
Description
CustomAlerts.addAlertandCustomAlerts.editAlertrequiredadditionalEmailsandphoneNumbers, even though both are optional lists. A request without them failed withPlease specify a value for additionalEmails. Most HTTP form encoders (PHPhttp_build_query, browsers, SDKs) drop empty arrays, so a client had no clean way to send "no entries". The only thing that worked was a placeholder entry likeadditionalEmails[]=, which is not documented.Root cause: the two parameters had no type and no default, so the API proxy treated them as required. With autosanitize it also treats an empty value (
additionalEmails=) as missing.Fix (API.php):
additionalEmailsandphoneNumbersare now typed?arrayin both methods. Parameter order is unchanged and there is no default, so there is no optional-before-required deprecation. For nullable parameters the core API proxy usesnullwhen the value is missing, so missing, null or empty values now reach the method asnull.filterPhoneNumbers()now returns[]for an empty or null list and skips empty or null entries.filterAdditionalEmails()already did this; both now cast entries to string beforetrim(), so[null]and['']also mean "no entries".Backward compatible: requests that send arrays work as before, including the
['']that the Vue edit form sends.reportMediumsis unchanged on purpose: at least one channel is still required.emailMealso still has no default and is not part of this change. As with any optional array parameter in Matomo, a non-array value (for exampleadditionalEmails=a@b.comwithout[]) is now treated as no entries. Before, it caused a PHP TypeError.Issue No
N/A: reported through partner API integration feedback, no GitHub issue.
Steps to Replicate the Issue
module=API&method=CustomAlerts.addAlert&name=Test&idSites[]=1&period=day&emailMe=1&metric=nb_visits&metricCondition=greater_than&metricValue=100&comparedTo=1&reportUniqueId=VisitsSummary_get&reportMediums[]=email&format=JSONplus a token, withoutadditionalEmailsorphoneNumbers.{"result":"error","message":"Please specify a value for additionalEmails"}. The same happens withadditionalEmails=&phoneNumbers=, and foreditAlert.How it was tested
tests/Integration/ApiTest.php:test_addAlert_shouldAcceptMissingOrEmptyOptionalListFieldsandtest_editAlert_shouldAcceptMissingOrEmptyOptionalListFields. They call the API throughRequest::processRequest. Each covers 6 input shapes: missing,[],null,[''],[null]and''. They failed before the fix (General_PleaseSpecifyValue) and pass after it. The wholeApiTest.phppasses (74 tests).API.php.[]=workaround worked. After the fix, all three create the alert, and the Manage Alerts page lists them.QA
Checked in a browser on a test install, following the bug's steps before and after the fix.
Steps:
Before the fix: addAlert without additionalEmails/phoneNumbers (or with empty values) fails with 'Please specify a value'; only the []= workaround works
Before the fix: Manage Alerts list only has the alert created with the workaround
After the fix: all three addAlert requests create the alert
After the fix: Manage Alerts lists the newly created QA alerts; page works normally
Checklist
🤖 Generated with Claude Code