Commit cd338706 authored by Alexander Kochetov's avatar Alexander Kochetov

Moved to framework/rbac + method names refactoring

parent 9158e110
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\web; namespace yii\rbac;
use Yii; use Yii;
use yii\base\Object; use yii\base\Object;
...@@ -16,7 +16,7 @@ use yii\base\Object; ...@@ -16,7 +16,7 @@ use yii\base\Object;
* @author Alexander Kochetov <creocoder@gmail.com> * @author Alexander Kochetov <creocoder@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class AuthAssignment extends Object class Assignment extends Object
{ {
private $_auth; private $_auth;
private $_itemName; private $_itemName;
...@@ -26,7 +26,7 @@ class AuthAssignment extends Object ...@@ -26,7 +26,7 @@ class AuthAssignment extends Object
/** /**
* Constructor. * Constructor.
* @param IAuthManager $auth the authorization manager * @param IManager $auth the authorization manager
* @param string $itemName authorization item name * @param string $itemName authorization item name
* @param mixed $userId user ID (see [[User::id]]) * @param mixed $userId user ID (see [[User::id]])
* @param string $bizRule the business rule associated with this assignment * @param string $bizRule the business rule associated with this assignment
...@@ -72,7 +72,7 @@ class AuthAssignment extends Object ...@@ -72,7 +72,7 @@ class AuthAssignment extends Object
{ {
if ($this->_bizRule !== $value) { if ($this->_bizRule !== $value) {
$this->_bizRule = $value; $this->_bizRule = $value;
$this->_auth->saveAuthAssignment($this); $this->_auth->saveAssignment($this);
} }
} }
...@@ -91,7 +91,7 @@ class AuthAssignment extends Object ...@@ -91,7 +91,7 @@ class AuthAssignment extends Object
{ {
if ($this->_data !== $value) { if ($this->_data !== $value) {
$this->_data = $value; $this->_data = $value;
$this->_auth->saveAuthAssignment($this); $this->_auth->saveAssignment($this);
} }
} }
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\web; namespace yii\rbac;
use Yii; use Yii;
use yii\base\Object; use yii\base\Object;
...@@ -16,7 +16,7 @@ use yii\base\Object; ...@@ -16,7 +16,7 @@ use yii\base\Object;
* @author Alexander Kochetov <creocoder@gmail.com> * @author Alexander Kochetov <creocoder@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class AuthItem extends Object class Item extends Object
{ {
const TYPE_OPERATION = 0; const TYPE_OPERATION = 0;
const TYPE_TASK = 1; const TYPE_TASK = 1;
...@@ -31,7 +31,7 @@ class AuthItem extends Object ...@@ -31,7 +31,7 @@ class AuthItem extends Object
/** /**
* Constructor. * Constructor.
* @param IAuthManager $auth authorization manager * @param IManager $auth authorization manager
* @param string $name authorization item name * @param string $name authorization item name
* @param integer $type authorization item type. This can be 0 (operation), 1 (task) or 2 (role). * @param integer $type authorization item type. This can be 0 (operation), 1 (task) or 2 (role).
* @param string $description the description * @param string $description the description
...@@ -51,7 +51,7 @@ class AuthItem extends Object ...@@ -51,7 +51,7 @@ class AuthItem extends Object
/** /**
* Checks to see if the specified item is within the hierarchy starting from this item. * Checks to see if the specified item is within the hierarchy starting from this item.
* This method is expected to be internally used by the actual implementations * This method is expected to be internally used by the actual implementations
* of the [[IAuthManager::checkAccess()]]. * of the [[IManager::checkAccess()]].
* @param string $itemName the name of the item to be checked * @param string $itemName the name of the item to be checked
* @param array $params the parameters to be passed to business rule evaluation * @param array $params the parameters to be passed to business rule evaluation
* @return boolean whether the specified item is within the hierarchy starting from this item. * @return boolean whether the specified item is within the hierarchy starting from this item.
...@@ -73,9 +73,9 @@ class AuthItem extends Object ...@@ -73,9 +73,9 @@ class AuthItem extends Object
} }
/** /**
* @return IAuthManager the authorization manager * @return IManager the authorization manager
*/ */
public function getAuthManager() public function getManager()
{ {
return $this->_auth; return $this->_auth;
} }
...@@ -104,7 +104,7 @@ class AuthItem extends Object ...@@ -104,7 +104,7 @@ class AuthItem extends Object
if ($this->_name !== $value) { if ($this->_name !== $value) {
$oldName = $this->_name; $oldName = $this->_name;
$this->_name = $value; $this->_name = $value;
$this->_auth->saveAuthItem($this, $oldName); $this->_auth->saveItem($this, $oldName);
} }
} }
...@@ -123,7 +123,7 @@ class AuthItem extends Object ...@@ -123,7 +123,7 @@ class AuthItem extends Object
{ {
if ($this->_description !== $value) { if ($this->_description !== $value) {
$this->_description = $value; $this->_description = $value;
$this->_auth->saveAuthItem($this); $this->_auth->saveItem($this);
} }
} }
...@@ -142,7 +142,7 @@ class AuthItem extends Object ...@@ -142,7 +142,7 @@ class AuthItem extends Object
{ {
if ($this->_bizRule !== $value) { if ($this->_bizRule !== $value) {
$this->_bizRule = $value; $this->_bizRule = $value;
$this->_auth->saveAuthItem($this); $this->_auth->saveItem($this);
} }
} }
...@@ -161,7 +161,7 @@ class AuthItem extends Object ...@@ -161,7 +161,7 @@ class AuthItem extends Object
{ {
if ($this->_data !== $value) { if ($this->_data !== $value) {
$this->_data = $value; $this->_data = $value;
$this->_auth->saveAuthItem($this); $this->_auth->saveItem($this);
} }
} }
...@@ -170,7 +170,7 @@ class AuthItem extends Object ...@@ -170,7 +170,7 @@ class AuthItem extends Object
* @param string $name the name of the child item * @param string $name the name of the child item
* @return boolean whether the item is added successfully * @return boolean whether the item is added successfully
* @throws \yii\base\Exception if either parent or child doesn't exist or if a loop has been detected. * @throws \yii\base\Exception if either parent or child doesn't exist or if a loop has been detected.
* @see IAuthManager::addItemChild * @see IManager::addItemChild
*/ */
public function addChild($name) public function addChild($name)
{ {
...@@ -182,7 +182,7 @@ class AuthItem extends Object ...@@ -182,7 +182,7 @@ class AuthItem extends Object
* Note, the child item is not deleted. Only the parent-child relationship is removed. * Note, the child item is not deleted. Only the parent-child relationship is removed.
* @param string $name the child item name * @param string $name the child item name
* @return boolean whether the removal is successful * @return boolean whether the removal is successful
* @see IAuthManager::removeItemChild * @see IManager::removeItemChild
*/ */
public function removeChild($name) public function removeChild($name)
{ {
...@@ -193,7 +193,7 @@ class AuthItem extends Object ...@@ -193,7 +193,7 @@ class AuthItem extends Object
* Returns a value indicating whether a child exists * Returns a value indicating whether a child exists
* @param string $name the child item name * @param string $name the child item name
* @return boolean whether the child exists * @return boolean whether the child exists
* @see IAuthManager::hasItemChild * @see IManager::hasItemChild
*/ */
public function hasChild($name) public function hasChild($name)
{ {
...@@ -203,7 +203,7 @@ class AuthItem extends Object ...@@ -203,7 +203,7 @@ class AuthItem extends Object
/** /**
* Returns the children of this item. * Returns the children of this item.
* @return array all child items of this item. * @return array all child items of this item.
* @see IAuthManager::getItemChildren * @see IManager::getItemChildren
*/ */
public function getChildren() public function getChildren()
{ {
...@@ -216,46 +216,46 @@ class AuthItem extends Object ...@@ -216,46 +216,46 @@ class AuthItem extends Object
* @param string $bizRule the business rule to be executed when [[checkAccess()]] is called * @param string $bizRule the business rule to be executed when [[checkAccess()]] is called
* for this particular authorization item. * for this particular authorization item.
* @param mixed $data additional data associated with this assignment * @param mixed $data additional data associated with this assignment
* @return AuthAssignment the authorization assignment information. * @return Assignment the authorization assignment information.
* @throws \yii\base\Exception if the item has already been assigned to the user * @throws \yii\base\Exception if the item has already been assigned to the user
* @see IAuthManager::assign * @see IManager::assign
*/ */
public function assign($userId, $bizRule = null, $data = null) public function assign($userId, $bizRule = null, $data = null)
{ {
return $this->_auth->assign($this->_name, $userId, $bizRule, $data); return $this->_auth->assign($userId, $this->_name, $bizRule, $data);
} }
/** /**
* Revokes an authorization assignment from a user. * Revokes an authorization assignment from a user.
* @param mixed $userId the user ID (see [[User::id]]) * @param mixed $userId the user ID (see [[User::id]])
* @return boolean whether removal is successful * @return boolean whether removal is successful
* @see IAuthManager::revoke * @see IManager::revoke
*/ */
public function revoke($userId) public function revoke($userId)
{ {
return $this->_auth->revoke($this->_name, $userId); return $this->_auth->revoke($userId, $this->_name);
} }
/** /**
* Returns a value indicating whether this item has been assigned to the user. * Returns a value indicating whether this item has been assigned to the user.
* @param mixed $userId the user ID (see [[User::id]]) * @param mixed $userId the user ID (see [[User::id]])
* @return boolean whether the item has been assigned to the user. * @return boolean whether the item has been assigned to the user.
* @see IAuthManager::isAssigned * @see IManager::isAssigned
*/ */
public function isAssigned($userId) public function isAssigned($userId)
{ {
return $this->_auth->isAssigned($this->_name, $userId); return $this->_auth->isAssigned($userId, $this->_name);
} }
/** /**
* Returns the item assignment information. * Returns the item assignment information.
* @param mixed $userId the user ID (see [[User::id]]) * @param mixed $userId the user ID (see [[User::id]])
* @return AuthAssignment the item assignment information. Null is returned if * @return Assignment the item assignment information. Null is returned if
* this item is not assigned to the user. * this item is not assigned to the user.
* @see IAuthManager::getAuthAssignment * @see IManager::getAssignment
*/ */
public function getAssignment($userId) public function getAssignment($userId)
{ {
return $this->_auth->getAuthAssignment($this->_name, $userId); return $this->_auth->getAssignment($userId, $this->_name);
} }
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\web; namespace yii\rbac;
use Yii; use Yii;
use yii\base\Component; use yii\base\Component;
...@@ -17,7 +17,7 @@ use yii\base\Exception; ...@@ -17,7 +17,7 @@ use yii\base\Exception;
* @author Alexander Kochetov <creocoder@gmail.com> * @author Alexander Kochetov <creocoder@gmail.com>
* @since 2.0 * @since 2.0
*/ */
abstract class AuthManager extends Component implements IAuthManager abstract class Manager extends Component implements IManager
{ {
/** /**
* @var boolean Enable error reporting for bizRules. * @var boolean Enable error reporting for bizRules.
...@@ -38,86 +38,86 @@ abstract class AuthManager extends Component implements IAuthManager ...@@ -38,86 +38,86 @@ abstract class AuthManager extends Component implements IAuthManager
/** /**
* Creates a role. * Creates a role.
* This is a shortcut method to [[IAuthManager::createAuthItem()]]. * This is a shortcut method to [[IManager::createItem()]].
* @param string $name the item name * @param string $name the item name
* @param string $description the item description. * @param string $description the item description.
* @param string $bizRule the business rule associated with this item * @param string $bizRule the business rule associated with this item
* @param mixed $data additional data to be passed when evaluating the business rule * @param mixed $data additional data to be passed when evaluating the business rule
* @return AuthItem the authorization item * @return Item the authorization item
*/ */
public function createRole($name, $description = '', $bizRule = null, $data = null) public function createRole($name, $description = '', $bizRule = null, $data = null)
{ {
return $this->createAuthItem($name, AuthItem::TYPE_ROLE, $description, $bizRule, $data); return $this->createItem($name, Item::TYPE_ROLE, $description, $bizRule, $data);
} }
/** /**
* Creates a task. * Creates a task.
* This is a shortcut method to [[IAuthManager::createAuthItem()]]. * This is a shortcut method to [[IManager::createItem()]].
* @param string $name the item name * @param string $name the item name
* @param string $description the item description. * @param string $description the item description.
* @param string $bizRule the business rule associated with this item * @param string $bizRule the business rule associated with this item
* @param mixed $data additional data to be passed when evaluating the business rule * @param mixed $data additional data to be passed when evaluating the business rule
* @return AuthItem the authorization item * @return Item the authorization item
*/ */
public function createTask($name, $description = '', $bizRule = null, $data = null) public function createTask($name, $description = '', $bizRule = null, $data = null)
{ {
return $this->createAuthItem($name, AuthItem::TYPE_TASK, $description, $bizRule, $data); return $this->createItem($name, Item::TYPE_TASK, $description, $bizRule, $data);
} }
/** /**
* Creates an operation. * Creates an operation.
* This is a shortcut method to [[IAuthManager::createAuthItem()]]. * This is a shortcut method to [[IManager::createItem()]].
* @param string $name the item name * @param string $name the item name
* @param string $description the item description. * @param string $description the item description.
* @param string $bizRule the business rule associated with this item * @param string $bizRule the business rule associated with this item
* @param mixed $data additional data to be passed when evaluating the business rule * @param mixed $data additional data to be passed when evaluating the business rule
* @return AuthItem the authorization item * @return Item the authorization item
*/ */
public function createOperation($name, $description = '', $bizRule = null, $data = null) public function createOperation($name, $description = '', $bizRule = null, $data = null)
{ {
return $this->createAuthItem($name, AuthItem::TYPE_OPERATION, $description, $bizRule, $data); return $this->createItem($name, Item::TYPE_OPERATION, $description, $bizRule, $data);
} }
/** /**
* Returns roles. * Returns roles.
* This is a shortcut method to [[IAuthManager::getAuthItems()]]. * This is a shortcut method to [[IManager::getItems()]].
* @param mixed $userId the user ID. If not null, only the roles directly assigned to the user * @param mixed $userId the user ID. If not null, only the roles directly assigned to the user
* will be returned. Otherwise, all roles will be returned. * will be returned. Otherwise, all roles will be returned.
* @return array roles (name=>AuthItem) * @return array roles (name=>AuthItem)
*/ */
public function getRoles($userId = null) public function getRoles($userId = null)
{ {
return $this->getAuthItems(AuthItem::TYPE_ROLE, $userId); return $this->getItems($userId, Item::TYPE_ROLE);
} }
/** /**
* Returns tasks. * Returns tasks.
* This is a shortcut method to [[IAuthManager::getAuthItems()]]. * This is a shortcut method to [[IManager::getItems()]].
* @param mixed $userId the user ID. If not null, only the tasks directly assigned to the user * @param mixed $userId the user ID. If not null, only the tasks directly assigned to the user
* will be returned. Otherwise, all tasks will be returned. * will be returned. Otherwise, all tasks will be returned.
* @return array tasks (name=>AuthItem) * @return array tasks (name=>AuthItem)
*/ */
public function getTasks($userId = null) public function getTasks($userId = null)
{ {
return $this->getAuthItems(AuthItem::TYPE_TASK, $userId); return $this->getItems($userId, Item::TYPE_TASK);
} }
/** /**
* Returns operations. * Returns operations.
* This is a shortcut method to [[IAuthManager::getAuthItems()]]. * This is a shortcut method to [[IManager::getItems()]].
* @param mixed $userId the user ID. If not null, only the operations directly assigned to the user * @param mixed $userId the user ID. If not null, only the operations directly assigned to the user
* will be returned. Otherwise, all operations will be returned. * will be returned. Otherwise, all operations will be returned.
* @return array operations (name=>AuthItem) * @return array operations (name=>AuthItem)
*/ */
public function getOperations($userId = null) public function getOperations($userId = null)
{ {
return $this->getAuthItems(AuthItem::TYPE_OPERATION, $userId); return $this->getItems($userId, Item::TYPE_OPERATION);
} }
/** /**
* Executes the specified business rule. * Executes the specified business rule.
* @param string $bizRule the business rule to be executed. * @param string $bizRule the business rule to be executed.
* @param array $params parameters passed to [[IAuthManager::checkAccess()]]. * @param array $params parameters passed to [[IManager::checkAccess()]].
* @param mixed $data additional data associated with the authorization item or assignment. * @param mixed $data additional data associated with the authorization item or assignment.
* @return boolean whether the business rule returns true. * @return boolean whether the business rule returns true.
* If the business rule is empty, it will still return true. * If the business rule is empty, it will still return true.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment