diff options
Diffstat (limited to 'core/Access.php')
-rw-r--r-- | core/Access.php | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/core/Access.php b/core/Access.php index 715b96aae0..931e958567 100644 --- a/core/Access.php +++ b/core/Access.php @@ -8,12 +8,15 @@ * @category Piwik * @package Piwik */ +namespace Piwik; + use Piwik\Config; use Piwik\Common; +use Piwik\Auth; /** * Class to handle User Access: - * - loads user access from the Piwik_Auth_Result object + * - loads user access from the AuthResult object * - provides easy to use API to check the permissions for the current (check* methods) * * In Piwik there are mainly 4 access levels @@ -34,9 +37,9 @@ use Piwik\Common; * and he only can change the main configuration settings. * * @package Piwik - * @subpackage Piwik_Access + * @subpackage Access */ -class Piwik_Access +class Access { private static $instance = null; @@ -142,7 +145,7 @@ class Piwik_Access * @param null|Piwik_Auth $auth Auth adapter * @return bool true on success, false if reloading access failed (when auth object wasn't specified and user is not enforced to be Super User) */ - public function reloadAccess(Piwik_Auth $auth = null) + public function reloadAccess(Auth $auth = null) { if (!is_null($auth)) { $this->auth = $auth; @@ -166,7 +169,7 @@ class Piwik_Access $this->token_auth = $result->getTokenAuth(); // case the superUser is logged in - if ($result->getCode() == Piwik_Auth_Result::SUCCESS_SUPERUSER_AUTH_CODE) { + if ($result->getCode() == AuthResult::SUCCESS_SUPERUSER_AUTH_CODE) { return $this->reloadAccessSuperUser(); } // in case multiple calls to API using different tokens, we ensure we reset it as not SU @@ -210,7 +213,7 @@ class Piwik_Access $this->isSuperUser = true; try { - $allSitesId = Piwik_SitesManager_API::getInstance()->getAllSitesId(); + $allSitesId = \Piwik_SitesManager_API::getInstance()->getAllSitesId(); } catch(Exception $e) { $allSitesId = array(); } @@ -328,19 +331,19 @@ class Piwik_Access /** * Throws an exception if the user is not the SuperUser * - * @throws Piwik_Access_NoAccessException + * @throws Access_NoAccessException */ public function checkUserIsSuperUser() { if (!$this->isSuperUser()) { - throw new Piwik_Access_NoAccessException(Piwik_TranslateException('General_ExceptionPrivilege', array("'superuser'"))); + throw new NoAccessException(Piwik_TranslateException('General_ExceptionPrivilege', array("'superuser'"))); } } /** * If the user doesn't have an ADMIN access for at least one website, throws an exception * - * @throws Piwik_Access_NoAccessException + * @throws Access_NoAccessException */ public function checkUserHasSomeAdminAccess() { @@ -349,14 +352,14 @@ class Piwik_Access } $idSitesAccessible = $this->getSitesIdWithAdminAccess(); if (count($idSitesAccessible) == 0) { - throw new Piwik_Access_NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAtLeastOneWebsite', array('admin'))); + throw new NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAtLeastOneWebsite', array('admin'))); } } /** * If the user doesn't have any view permission, throw exception * - * @throws Piwik_Access_NoAccessException + * @throws Access_NoAccessException */ public function checkUserHasSomeViewAccess() { @@ -365,7 +368,7 @@ class Piwik_Access } $idSitesAccessible = $this->getSitesIdWithAtLeastViewAccess(); if (count($idSitesAccessible) == 0) { - throw new Piwik_Access_NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAtLeastOneWebsite', array('view'))); + throw new NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAtLeastOneWebsite', array('view'))); } } @@ -374,7 +377,7 @@ class Piwik_Access * If the user doesn't have ADMIN access for at least one website of the list, we throw an exception. * * @param int|array $idSites List of ID sites to check - * @throws Piwik_Access_NoAccessException If for any of the websites the user doesn't have an ADMIN access + * @throws Access_NoAccessException If for any of the websites the user doesn't have an ADMIN access */ public function checkUserHasAdminAccess($idSites) { @@ -385,7 +388,7 @@ class Piwik_Access $idSitesAccessible = $this->getSitesIdWithAdminAccess(); foreach ($idSites as $idsite) { if (!in_array($idsite, $idSitesAccessible)) { - throw new Piwik_Access_NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAccessWebsite', array("'admin'", $idsite))); + throw new NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAccessWebsite', array("'admin'", $idsite))); } } } @@ -395,7 +398,7 @@ class Piwik_Access * If the user doesn't have VIEW or ADMIN access for at least one website of the list, we throw an exception. * * @param int|array|string $idSites List of ID sites to check (integer, array of integers, string comma separated list of integers) - * @throws Piwik_Access_NoAccessException If for any of the websites the user doesn't have an VIEW or ADMIN access + * @throws Access_NoAccessException If for any of the websites the user doesn't have an VIEW or ADMIN access */ public function checkUserHasViewAccess($idSites) { @@ -406,7 +409,7 @@ class Piwik_Access $idSitesAccessible = $this->getSitesIdWithAtLeastViewAccess(); foreach ($idSites as $idsite) { if (!in_array($idsite, $idSitesAccessible)) { - throw new Piwik_Access_NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAccessWebsite', array("'view'", $idsite))); + throw new NoAccessException(Piwik_TranslateException('General_ExceptionPrivilegeAccessWebsite', array("'view'", $idsite))); } } } @@ -414,7 +417,7 @@ class Piwik_Access /** * @param int|array|string $idSites * @return array - * @throws Piwik_Access_NoAccessException + * @throws Access_NoAccessException */ protected function getIdSites($idSites) { @@ -422,9 +425,9 @@ class Piwik_Access $idSites = $this->getSitesIdWithAtLeastViewAccess(); } - $idSites = Piwik_Site::getIdSitesFromIdSitesString($idSites); + $idSites = \Piwik_Site::getIdSitesFromIdSitesString($idSites); if (empty($idSites)) { - throw new Piwik_Access_NoAccessException("The parameter 'idSite=' is missing from the request."); + throw new NoAccessException("The parameter 'idSite=' is missing from the request."); } return $idSites; } @@ -434,8 +437,8 @@ class Piwik_Access * Exception thrown when a user doesn't have sufficient access. * * @package Piwik - * @subpackage Piwik_Access + * @subpackage Access */ -class Piwik_Access_NoAccessException extends Exception +class NoAccessException extends \Exception { } |