diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2020-07-21 02:51:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-21 02:51:37 +0300 |
commit | 2c998d20227c26651a4f6599302335b322f1d04a (patch) | |
tree | 8c0ae5ddc74a5a22d63c7bf9168f7504c32202f5 /plugins | |
parent | 6b6dc723c73dc4d59b2ae849d241270dc53e5a39 (diff) |
Allow plugins to configure custom user preferences (#16210)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/UsersManager/API.php | 16 | ||||
-rw-r--r-- | plugins/UsersManager/config/config.php | 4 | ||||
-rw-r--r-- | plugins/UsersManager/tests/Integration/APITest.php | 1 |
3 files changed, 15 insertions, 6 deletions
diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 011b07a8c2..64c2313bdf 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -179,7 +179,13 @@ class API extends \Piwik\Plugin\API } /** - * Sets a user preference + * Sets a user preference. Plugins can add custom preference names by declaring them in their plugin config/config.php + * like this: + * + * ```php + * return array('usersmanager.user_preference_names' => DI\add(array('preference_name_1', 'preference_name_2'))); + * ``` + * * @param string $userLogin * @param string $preferenceName * @param string $preferenceValue @@ -282,11 +288,11 @@ class API extends \Piwik\Plugin\API self::PREFERENCE_DEFAULT_REPORT_DATE, 'isLDAPUser', // used in loginldap 'hideSegmentDefinitionChangeMessage',// used in JS - 'randomDoesNotExist',// for tests - 'RandomNOTREQUESTED',// for tests - 'preferenceName'// for tests ); - if (!in_array($preference, $names, true)) { + $customPreferences = StaticContainer::get('usersmanager.user_preference_names'); + + if (!in_array($preference, $names, true) + && !in_array($preference, $customPreferences, true)) { throw new Exception('Not supported preference name: ' . $preference); } return $login . self::OPTION_NAME_PREFERENCE_SEPARATOR . $preference; diff --git a/plugins/UsersManager/config/config.php b/plugins/UsersManager/config/config.php index d266508bcd..4463e40397 100644 --- a/plugins/UsersManager/config/config.php +++ b/plugins/UsersManager/config/config.php @@ -1,2 +1,4 @@ <?php -return array(); +return array( + 'usersmanager.user_preference_names' => [] +); diff --git a/plugins/UsersManager/tests/Integration/APITest.php b/plugins/UsersManager/tests/Integration/APITest.php index db110571e8..7a5574c731 100644 --- a/plugins/UsersManager/tests/Integration/APITest.php +++ b/plugins/UsersManager/tests/Integration/APITest.php @@ -1033,6 +1033,7 @@ class APITest extends IntegrationTestCase { return array( 'Piwik\Access' => new FakeAccess(), + 'usersmanager.user_preference_names' => \DI\add(['randomDoesNotExist', 'RandomNOTREQUESTED', 'preferenceName']), 'observers.global' => \DI\add([ ['Access.Capability.addCapabilities', function (&$capabilities) { $capabilities[] = new TestCap1(); |