diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2020-06-02 23:15:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-02 23:15:12 +0300 |
commit | fb8a9d2d0f1ea2b07558f2a05cad29a35b3141cb (patch) | |
tree | 80b3ff57a3269267ee7cdd1626133908dbfba316 | |
parent | 52262868d6c9f3773d37096e1450910e88ad5fd8 (diff) |
Optional userLogin in getUserPreference API (#16010)
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | plugins/UsersManager/API.php | 10 | ||||
-rw-r--r-- | plugins/UsersManager/tests/System/ApiTest.php | 32 | ||||
-rw-r--r-- | tests/UI/expected-screenshots/UIIntegrationTest_api_listing.png | 4 |
4 files changed, 48 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e0a2a5cc8..77eceed363 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ This is the Developer Changelog for Matomo platform developers. All changes in o The Product Changelog at **[matomo.org/changelog](https://matomo.org/changelog)** lets you see more details about any Matomo release, such as the list of new guides and FAQs, security fixes, and links to all closed issues. +## Matomo 3.13.6 + +### API Changes +* The first parameter `userLogin` in the `UsersManager.getUserPreference` method is now optional and defaults to the currently authenticated user login. + ## Matomo 3.13.5 ### New API @@ -853,6 +858,7 @@ We are using `@since` annotations in case we are introducing new API's to make i ### Breaking Changes ### Deprecations +### API Changes ### New features ### New APIs ### New commands diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 08cf1312c0..51f09107a6 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -193,12 +193,18 @@ class API extends \Piwik\Plugin\API /** * Gets a user preference - * @param string $userLogin + * @param string $userLogin Optional, defaults to current user log in. * @param string $preferenceName * @return bool|string */ - public function getUserPreference($userLogin, $preferenceName) + public function getUserPreference($userLogin = false, $preferenceName) { + if ($userLogin === false) { + // the default value for first parameter is there to have it an optional parameter in the HTTP API + // in PHP it won't be optional. Could move parameter to the end of the method but did not want to break + // BC + $userLogin = Piwik::getCurrentUserLogin(); + } Piwik::checkUserHasSuperUserAccessOrIsTheUser($userLogin); $optionValue = $this->getPreferenceValue($userLogin, $preferenceName); diff --git a/plugins/UsersManager/tests/System/ApiTest.php b/plugins/UsersManager/tests/System/ApiTest.php index 0a7d808ffb..2d7af69ebe 100644 --- a/plugins/UsersManager/tests/System/ApiTest.php +++ b/plugins/UsersManager/tests/System/ApiTest.php @@ -8,6 +8,9 @@ namespace Piwik\Plugins\UsersManager\tests\System; +use Piwik\API\Request; +use Piwik\Piwik; +use Piwik\Plugins\UsersManager\API; use Piwik\Plugins\UsersManager\tests\Fixtures\ManyUsers; use Piwik\Tests\Framework\TestCase\SystemTestCase; @@ -44,6 +47,35 @@ class ApiTest extends SystemTestCase } } + public function test_getUserPreference_loginIsOptional() + { + $response = Request::processRequest('UsersManager.getUserPreference', array( + 'preferenceName' => API::PREFERENCE_DEFAULT_REPORT + )); + $this->assertEquals('1', $response); + + $response = Request::processRequest('UsersManager.getUserPreference', array( + 'preferenceName' => API::PREFERENCE_DEFAULT_REPORT_DATE + )); + $this->assertEquals('yesterday', $response); + } + + public function test_getUserPreference_loginCanBeSet() + { + $response = Request::processRequest('UsersManager.getUserPreference', array( + 'userLogin' => Piwik::getCurrentUserLogin(), + 'preferenceName' => API::PREFERENCE_DEFAULT_REPORT_DATE + )); + $this->assertEquals('yesterday', $response); + + // user not exists + $response = Request::processRequest('UsersManager.getUserPreference', array( + 'userLogin' => 'foo', + 'preferenceName' => API::PREFERENCE_DEFAULT_REPORT_DATE + )); + $this->assertEquals('yesterday', $response); + } + public function getApiForTesting() { $apiToTest = array( diff --git a/tests/UI/expected-screenshots/UIIntegrationTest_api_listing.png b/tests/UI/expected-screenshots/UIIntegrationTest_api_listing.png index 453a2aa9c0..c30a97748b 100644 --- a/tests/UI/expected-screenshots/UIIntegrationTest_api_listing.png +++ b/tests/UI/expected-screenshots/UIIntegrationTest_api_listing.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fba29ae0960d5f150636b462d060d3407573d9aa31e4467e98b5d80a38e94ecb -size 4943071 +oid sha256:b4668beaae48a9761a8833a3d0cb57df6765a0d8f404ea29d7dac0434b7891f1 +size 4943329 |