setUserAccess() public method

If access = 'noaccess' the current access (if any) will be deleted. If access = 'view' or 'admin' the current access level is deleted and updated with the new value.
public setUserAccess ( string $userLogin, string $access, integer | array $idSites ) : boolean
$userLogin string The user login
$access string Access to grant. Must have one of the following value : noaccess, view, admin
$idSites integer | array The array of idSites on which to apply the access level for the user. If the value is "all" then we apply the access level to all the websites ID for which the current authentificated user has an 'admin' access.
return boolean true on success
Esempio n. 1
0
 public function test_setUserAccess_ShouldNotTriggerRemoveSiteAccessEvent_IfAccessIsAdded()
 {
     $eventTriggered = false;
     Piwik::addAction('UsersManager.removeSiteAccess', function () use(&$eventTriggered) {
         $eventTriggered = true;
     });
     $this->api->setUserAccess($this->login, 'admin', array(1, 2));
     $this->assertFalse($eventTriggered, 'UsersManager.removeSiteAccess event was triggered but should not');
 }
 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'));
 }