If the user doesn't have any access to a website ('noaccess'),
this website will not be in the returned array.
If the user doesn't have any access, the returned array will be an empty array.
public getSitesAccessFromUser ( string $userLogin ) : array | ||
$userLogin | string | User that has to be valid |
Résultat | array | The returned array has the format array( idsite1 => 'view', idsite2 => 'admin', idsite3 => 'view', ... ) |
/** * For each website ID, returns the access level of the given $userLogin. * If the user doesn't have any access to a website ('noaccess'), * this website will not be in the returned array. * If the user doesn't have any access, the returned array will be an empty array. * * @param string $userLogin User that has to be valid * * @return array The returned array has the format * array( * idsite1 => 'view', * idsite2 => 'admin', * idsite3 => 'view', * ... * ) */ public function getSitesAccessFromUser($userLogin) { Piwik::checkUserHasSuperUserAccess(); $this->checkUserExists($userLogin); $this->checkUserHasNotSuperUserAccess($userLogin); return $this->model->getSitesAccessFromUser($userLogin); }
public function testSetSuperUserAccess_ShouldDeleteAllExistingAccessEntries() { list($id1, $id2) = $this->addSites(2); $this->api->addUser('login1', 'password1', '*****@*****.**', false); $this->api->setUserAccess('login1', 'view', array($id1)); $this->api->setUserAccess('login1', 'admin', array($id2)); // verify user has access before setting Super User access $access = $this->_flatten($this->api->getSitesAccessFromUser('login1')); $this->assertEquals(array($id1 => 'view', $id2 => 'admin'), $access); $this->api->setSuperUserAccess('login1', true); // verify no longer any access $this->assertEquals(array(), $this->model->getSitesAccessFromUser('login1')); }
/** * For each website ID, returns the access level of the given $userLogin. * If the user doesn't have any access to a website ('noaccess'), * this website will not be in the returned array. * If the user doesn't have any access, the returned array will be an empty array. * * @param string $userLogin User that has to be valid * * @return array The returned array has the format * array( * idsite1 => 'view', * idsite2 => 'admin', * idsite3 => 'view', * ... * ) */ public function getSitesAccessFromUser($userLogin) { Piwik::checkUserHasSuperUserAccess(); $this->checkUserExists($userLogin); // Super users have 'admin' access for every site if (Piwik::hasTheUserSuperUserAccess($userLogin)) { $return = array(); $siteManagerModel = Factory::getModel('Piwik\\Plugins\\SitesManager'); $sites = $siteManagerModel->getAllSites(); foreach ($sites as $site) { $return[] = array('site' => $site['idsite'], 'access' => 'admin'); } return $return; } return $this->model->getSitesAccessFromUser($userLogin); }