diff options
author | sgiehl <stefan@piwik.org> | 2015-03-14 20:54:42 +0300 |
---|---|---|
committer | sgiehl <stefan@piwik.org> | 2015-03-14 20:54:42 +0300 |
commit | 3317ff82ffe45056a3fd9efb18c04b164ea25071 (patch) | |
tree | 9c77cadc0a32a7372eda0d1e23be393b7d7d40cd /plugins | |
parent | 17339285b84b9140dea8997d40e54db78c7bf815 (diff) |
fixes #6359 - make UsersManager.getSitesAccessFromUser work for superuser
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/UsersManager/API.php | 16 | ||||
-rw-r--r-- | plugins/UsersManager/tests/Integration/APITest.php | 29 |
2 files changed, 44 insertions, 1 deletions
diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php index 23ee2206d9..b1c7c227e3 100644 --- a/plugins/UsersManager/API.php +++ b/plugins/UsersManager/API.php @@ -276,7 +276,21 @@ class API extends \Piwik\Plugin\API { Piwik::checkUserHasSuperUserAccess(); $this->checkUserExists($userLogin); - $this->checkUserHasNotSuperUserAccess($userLogin); + + // Super users have 'admin' access for every site + if (Piwik::hasTheUserSuperUserAccess($userLogin)) { + $return = array(); + $siteManagerModel = new \Piwik\Plugins\SitesManager\Model(); + $sites = $siteManagerModel->getAllSites(); + foreach ($sites as $site) { + $return[] = array( + 'site' => $site['idsite'], + 'access' => 'admin' + ); + + } + return $return; + } return $this->model->getSitesAccessFromUser($userLogin); } diff --git a/plugins/UsersManager/tests/Integration/APITest.php b/plugins/UsersManager/tests/Integration/APITest.php index 5bd81f75c6..d743ca01a0 100644 --- a/plugins/UsersManager/tests/Integration/APITest.php +++ b/plugins/UsersManager/tests/Integration/APITest.php @@ -135,4 +135,33 @@ class APITest extends IntegrationTestCase $this->api->setUserPreference($user2, 'ohOH_myPreferenceName', 'valueForUser2'); } + public function test_getSitesAccessFromUser_forSuperUser() + { + $user2 = 'userLogin2'; + $this->api->addUser($user2, 'password', 'userlogin2@password.de'); + + // new user doesn't have access to anything + $access = $this->api->getSitesAccessFromUser($user2); + $this->assertEmpty($access); + + $this->api->setSuperUserAccess($user2, true); + + // super user has admin access for every site + $access = $this->api->getSitesAccessFromUser($user2); + $expected = array( + array( + 'site' => 1, + 'access' => 'admin' + ), + array( + 'site' => 2, + 'access' => 'admin' + ), + array( + 'site' => 3, + 'access' => 'admin' + ), + ); + $this->assertEquals($expected, $access); + } } |