From 9841d6c639e87b80c6b2a90a528deeff808ac33a Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 5 May 2013 15:11:53 -0400 Subject: [PATCH] Fixes issue #124. --- framework/base/Application.php | 9 +++++++++ framework/web/AccessRule.php | 2 +- framework/web/User.php | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/framework/base/Application.php b/framework/base/Application.php index 6dca5cf..5b92f76 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -306,6 +306,15 @@ class Application extends Module } /** + * @return null|Component + * @todo + */ + public function getAuthManager() + { + return $this->getComponent('auth'); + } + + /** * Registers the core application components. * @see setComponents */ diff --git a/framework/web/AccessRule.php b/framework/web/AccessRule.php index 3f8c057..1bcb896 100644 --- a/framework/web/AccessRule.php +++ b/framework/web/AccessRule.php @@ -144,7 +144,7 @@ class AccessRule extends Component return true; } elseif ($role === '@' && !$user->getIsGuest()) { return true; - } elseif ($user->hasAccess($role)) { + } elseif ($user->checkAccess($role)) { return true; } } diff --git a/framework/web/User.php b/framework/web/User.php index b8bf7cd..2fbea91 100644 --- a/framework/web/User.php +++ b/framework/web/User.php @@ -447,4 +447,21 @@ class User extends Component } } } + + /** + * Checks whether the user has access to the specified operation. + * @param $operator + * @param array $params + * @return bool + * @todo + */ + public function checkAccess($operation, $params = array()) + { + $auth = Yii::$app->getAuthManager(); + if ($auth !== null) { + return $auth->checkAccess($this->getId(), $operation, $params); + } else { + return true; + } + } }