revoke() public method

Revokes a role from a user.
public revoke ( Role $role, string | integer $userId ) : boolean
$role Role
$userId string | integer the user ID (see [[\yii\web\User::id]])
return boolean whether the revoking is successful
コード例 #1
0
ファイル: AssignmentModel.php プロジェクト: yii2mod/yii2-rbac
 /**
  * Revokes a roles and permissions from the user.
  *
  * @param array $items
  *
  * @return int number of successful revoke
  */
 public function revoke($items)
 {
     foreach ($items as $name) {
         $item = $this->manager->getRole($name);
         $item = $item ?: $this->manager->getPermission($name);
         $this->manager->revoke($item, $this->userId);
     }
     return true;
 }
コード例 #2
0
 /**
  * Remove roles.
  */
 protected function removeRoles()
 {
     if (!($roles = ArrayHelper::getValue($this->rbac, 'roles'))) {
         return;
     }
     foreach ($roles as $name => $children) {
         if (!($role = $this->_auth->getRole($name))) {
             continue;
         }
         foreach ($children as $childName) {
             if ($permission = ArrayHelper::getValue($this->_permissions, $childName)) {
                 $this->_auth->removeChild($role, $permission);
             } elseif ($childRole = $this->_auth->getRole($childName)) {
                 $this->_auth->removeChild($role, $childRole);
             }
         }
         $this->_auth->remove($role);
         $userIds = $this->_auth->getUserIdsByRole($name);
         foreach ($userIds as $userId) {
             $this->_auth->revoke($role, $userId);
         }
     }
 }