getUsersAccessFromSite() public method

public getUsersAccessFromSite ( $idSite )
Ejemplo n.º 1
0
 /**
  * For each user, returns his access level for the given $idSite.
  * If a user doesn't have any access to the $idSite ('noaccess'),
  * the user will not be in the returned array.
  *
  * @param int $idSite website ID
  *
  * @return array    The returned array has the format
  *                    array(
  *                        login1 => 'view',
  *                        login2 => 'admin',
  *                        login3 => 'view',
  *                        ...
  *                    )
  */
 public function getUsersAccessFromSite($idSite)
 {
     Piwik::checkUserHasAdminAccess($idSite);
     $usersAccess = $this->model->getUsersAccessFromSite($idSite);
     $usersAccess = $this->userFilter->filterLoginIndexedArray($usersAccess);
     return $usersAccess;
 }
 /**
  * Authenticates user
  *
  * @return AuthResult
  */
 public function authenticate()
 {
     $logger = StaticContainer::get('Psr\\Log\\LoggerInterface');
     $model = new Model();
     $user = $model->getUser($this->login);
     if (!$user) {
         $user = $model->getUserByTokenAuth($this->token_auth);
         if (!$user) {
             $logger->info("Creating user " . $this->login);
             $model->addUser($this->login, $this->getTokenAuthSecret(), $this->email, $this->alias, $this->token_auth, Date::now()->getDatetime());
             $user = $model->getUser($this->login);
         }
     }
     $accessCode = $user['superuser_access'] ? AuthResult::SUCCESS_SUPERUSER_AUTH_CODE : AuthResult::SUCCESS;
     $this->login = $user['login'];
     if ($this->getViewableUserStatus() || $this->getSuperUserStatus()) {
         $site_ids = $this->getDefaultSiteIds();
         $current_accesses = array();
         foreach ($site_ids as $site_id) {
             $accesses = $model->getUsersAccessFromSite($site_id);
             foreach ($accesses as $user => $access) {
                 if ($this->login == $user && ($access == "view" || $access == 'admin')) {
                     $current_accesses[] = $site_id;
                 }
             }
         }
         $new_accesses = array();
         foreach ($site_ids as $site_id) {
             if (!in_array($site_id, $current_accesses)) {
                 $new_accesses[] = $site_id;
             }
         }
         if (count($new_accesses) > 0) {
             $logger->info("Adding default site ids to " . $this->login);
             $model->addUserAccess($this->login, "view", $new_accesses);
         }
     }
     $is_superuser = $this->getSuperUserStatus();
     $model->setSuperUserAccess($this->login, $is_superuser);
     return new AuthResult($accessCode, $this->login, $this->token_auth);
 }
Ejemplo n.º 3
0
 /**
  * For each user, returns his access level for the given $idSite.
  * If a user doesn't have any access to the $idSite ('noaccess'),
  * the user will not be in the returned array.
  *
  * @param int $idSite website ID
  *
  * @return array    The returned array has the format
  *                    array(
  *                        login1 => 'view',
  *                        login2 => 'admin',
  *                        login3 => 'view',
  *                        ...
  *                    )
  */
 public function getUsersAccessFromSite($idSite)
 {
     Piwik::checkUserHasAdminAccess($idSite);
     return $this->model->getUsersAccessFromSite($idSite);
 }