Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Giehl <stefan@piwik.org>2018-03-20 13:09:27 +0300
committerMatthieu Aubry <mattab@users.noreply.github.com>2018-03-20 13:09:27 +0300
commit4bf917cbdb8ff92e37ea312d1960ab8966a919c2 (patch)
treec48b9c3fbe375040daa11bfaba8fd7066a5390ef /plugins/Dashboard/API.php
parentb7a5b45f605c1aed6062726ff73879fd990241eb (diff)
Further improvements to Dashboard API (#12609)
* Further improvements to Dashboard API * adds some tests
Diffstat (limited to 'plugins/Dashboard/API.php')
-rw-r--r--plugins/Dashboard/API.php24
1 files changed, 18 insertions, 6 deletions
diff --git a/plugins/Dashboard/API.php b/plugins/Dashboard/API.php
index 7ebcb84fcd..e646499f48 100644
--- a/plugins/Dashboard/API.php
+++ b/plugins/Dashboard/API.php
@@ -27,15 +27,26 @@ class API extends \Piwik\Plugin\API
/**
* Get each dashboard that belongs to a user including the containing widgets that are placed within each dashboard.
- * If the user has not created any dashboard yet, the default dashboard will be returned.
+ * If the user has not created any dashboard yet, the default dashboard will be returned unless
+ * $returnDefaultIfEmpty is set to `false`
+ *
+ * @param string $login Login of the user [defaults to current user]
+ * @param bool $returnDefaultIfEmpty disable return of default dashboard
*
* @return array[]
*/
- public function getDashboards()
+ public function getDashboards($login = '', $returnDefaultIfEmpty = true)
{
- $dashboards = $this->getUserDashboards();
+ $login = $login ? $login : Piwik::getCurrentUserLogin();
+
+ $dashboards = [];
- if (empty($dashboards)) {
+ if (!Piwik::isUserIsAnonymous()) {
+ Piwik::checkUserHasSuperUserAccessOrIsTheUser($login);
+ $dashboards = $this->getUserDashboards($login);
+ }
+
+ if (empty($dashboards) && $returnDefaultIfEmpty) {
$dashboards = array($this->getDefaultDashboard());
}
@@ -150,11 +161,12 @@ class API extends \Piwik\Plugin\API
/**
* Get all dashboards which a user has created.
+ *
+ * @param string $userLogin login of the user
* @return \array[]
*/
- private function getUserDashboards()
+ private function getUserDashboards($userLogin)
{
- $userLogin = Piwik::getCurrentUserLogin();
$userDashboards = $this->dashboard->getAllDashboards($userLogin);
$dashboards = array();