diff options
author | sgiehl <stefan@matomo.org> | 2020-07-24 14:11:05 +0300 |
---|---|---|
committer | sgiehl <stefan@matomo.org> | 2020-07-24 15:28:48 +0300 |
commit | 679e73f1236969db0c2d767655cb84456a727d24 (patch) | |
tree | 648722fa79cb524f8819857e79163e0c1cf16d59 /plugins/UsersManager/API.php | |
parent | 6b5f8138180716d5088d764f0b41d5787159b28a (diff) | |
parent | 3e1234a887f56a1cf853e29ba89370b234af5127 (diff) |
Merge branch '3.x-dev' into 4.x-dev
Diffstat (limited to 'plugins/UsersManager/API.php')
-rw-r--r-- | plugins/UsersManager/API.php | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 5286973b84..1b64000e23 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 @@ -188,7 +194,17 @@ class API extends \Piwik\Plugin\API public function setUserPreference($userLogin, $preferenceName, $preferenceValue) { Piwik::checkUserHasSuperUserAccessOrIsTheUser($userLogin); - Option::set($this->getPreferenceId($userLogin, $preferenceName), $preferenceValue); + + if (!$this->model->userExists($userLogin)) { + throw new Exception('User does not exist: ' . $userLogin); + } + + if ($userLogin === 'anonymous') { + Piwik::checkUserHasSuperUserAccess(); + } + + $nameIfSupported = $this->getPreferenceId($userLogin, $preferenceName); + Option::set($nameIfSupported, $preferenceValue); } /** @@ -267,6 +283,18 @@ class API extends \Piwik\Plugin\API if(false !== strpos($preference, self::OPTION_NAME_PREFERENCE_SEPARATOR)) { throw new Exception("Preference name cannot contain underscores."); } + $names = array( + self::PREFERENCE_DEFAULT_REPORT, + self::PREFERENCE_DEFAULT_REPORT_DATE, + 'isLDAPUser', // used in loginldap + 'hideSegmentDefinitionChangeMessage',// used in JS + ); + $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; } |