Browse Source

Fixes #10726: Added `yii\rbac\ManagerInterface::canAddChild()`

tags/2.0.8
Dmitry Khlystov 9 years ago committed by Alexander Makarov
parent
commit
7eff23886c
  1. 1
      framework/CHANGELOG.md
  2. 2
      framework/UPGRADE.md
  3. 8
      framework/rbac/DbManager.php
  4. 10
      framework/rbac/ManagerInterface.php
  5. 10
      framework/rbac/PhpManager.php
  6. 12
      tests/framework/rbac/ManagerTestCase.php

1
framework/CHANGELOG.md

@ -28,6 +28,7 @@ Yii Framework 2 Change Log
- Eng #10976: `Inflector::transliterate()` now uses `strtr` instead of `str_replace` (DrDeath72) - Eng #10976: `Inflector::transliterate()` now uses `strtr` instead of `str_replace` (DrDeath72)
- Bug #11040: Check parameter 'recursive' and disable recursive copying with option 'recursive' => false in method BaseFileHelper::copyDirectory (Ni-san) - Bug #11040: Check parameter 'recursive' and disable recursive copying with option 'recursive' => false in method BaseFileHelper::copyDirectory (Ni-san)
- Chg: HTMLPurifier dependency updated to `~4.6` (samdark) - Chg: HTMLPurifier dependency updated to `~4.6` (samdark)
- Chg #10726: Added `yii\rbac\ManagerInterface::canAddChild()` (dkhlystov, samdark)
- Chg #11071: `yii\helpers\BaseArrayHelper::isIn()` and `isTraversable()` since now throw `\yii\base\InvalidParamException` instead of `\InvalidArgumentException` (nukkumatti) - Chg #11071: `yii\helpers\BaseArrayHelper::isIn()` and `isTraversable()` since now throw `\yii\base\InvalidParamException` instead of `\InvalidArgumentException` (nukkumatti)
2.0.7 February 14, 2016 2.0.7 February 14, 2016

2
framework/UPGRADE.md

@ -22,6 +22,8 @@ ______________________
* `yii\helpers\BaseArrayHelper` methods `isIn()` and `isSubset()` throw `\yii\base\InvalidParamException` * `yii\helpers\BaseArrayHelper` methods `isIn()` and `isSubset()` throw `\yii\base\InvalidParamException`
instead of `\InvalidArgumentException`. If you wrap calls of these methods in try/catch block, change expected instead of `\InvalidArgumentException`. If you wrap calls of these methods in try/catch block, change expected
exception class. exception class.
- `yii\rbac\ManagerInterface::canAddChild()` method was added. If you have custom backend for RBAC you need to implement
it.
Upgrade from Yii 2.0.6 Upgrade from Yii 2.0.6

8
framework/rbac/DbManager.php

@ -679,6 +679,14 @@ class DbManager extends BaseManager
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function canAddChild($parent, $child)
{
return !$this->detectLoop($parent, $child);
}
/**
* @inheritdoc
*/
public function addChild($parent, $child) public function addChild($parent, $child)
{ {
if ($parent->name === $child->name) { if ($parent->name === $child->name) {

10
framework/rbac/ManagerInterface.php

@ -129,6 +129,16 @@ interface ManagerInterface
public function getRules(); public function getRules();
/** /**
* Checks the possibility of adding a child to parent
* @param Item $parent the parent item
* @param Item $child the child item to be added to the hierarchy
* @return boolean possibility of adding
*
* @since 2.0.8
*/
public function canAddChild($parent, $child);
/**
* Adds an item as a child of another item. * Adds an item as a child of another item.
* @param Item $parent * @param Item $parent
* @param Item $child * @param Item $child

10
framework/rbac/PhpManager.php

@ -151,6 +151,14 @@ class PhpManager extends BaseManager
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function canAddChild($parent, $child)
{
return !$this->detectLoop($parent, $child);
}
/**
* @inheritdoc
*/
public function addChild($parent, $child) public function addChild($parent, $child)
{ {
if (!isset($this->items[$parent->name], $this->items[$child->name])) { if (!isset($this->items[$parent->name], $this->items[$child->name])) {
@ -817,7 +825,7 @@ class PhpManager extends BaseManager
$result = []; $result = [];
foreach ($this->assignments as $userID => $assignments) { foreach ($this->assignments as $userID => $assignments) {
foreach ($assignments as $userAssignment) { foreach ($assignments as $userAssignment) {
if ($userAssignment->roleName === $roleName && $userAssignment->userId === $userID) { if ($userAssignment->roleName === $roleName && $userAssignment->userId == $userID) {
$result[] = (string)$userID; $result[] = (string)$userID;
} }
} }

12
tests/framework/rbac/ManagerTestCase.php

@ -312,4 +312,16 @@ abstract class ManagerTestCase extends TestCase
$this->assertEquals(['author B'], $this->auth->getUserIdsByRole('author')); $this->assertEquals(['author B'], $this->auth->getUserIdsByRole('author'));
$this->assertEquals(['admin C'], $this->auth->getUserIdsByRole('admin')); $this->assertEquals(['admin C'], $this->auth->getUserIdsByRole('admin'));
} }
public function testCanAddChild()
{
$this->prepareData();
$author = $this->auth->createRole('author');
$reader = $this->auth->createRole('reader');
$this->assertTrue($this->auth->canAddChild($author, $reader));
$this->assertFalse($this->auth->canAddChild($reader, $author));
}
} }

Loading…
Cancel
Save