Fix #18196: yii\rbac\DbManager::$checkAccessAssignments is now protected

This commit is contained in:
Alex
2020-09-08 10:16:39 +01:00
committed by GitHub
parent db4beebe23
commit 287476465d
2 changed files with 14 additions and 11 deletions

View File

@ -10,6 +10,7 @@ Yii Framework 2 Change Log
- Enh #18236: Allow `yii\filters\RateLimiter` to accept a closure function for the `$user` property in order to assign values on runtime (nadar) - Enh #18236: Allow `yii\filters\RateLimiter` to accept a closure function for the `$user` property in order to assign values on runtime (nadar)
- Bug #18248: Render only one stack trace on console for chained exceptions (mikehaertl) - Bug #18248: Render only one stack trace on console for chained exceptions (mikehaertl)
- Bug #18233: Add PHP 8 support (samdark) - Bug #18233: Add PHP 8 support (samdark)
- Enh #18196: `yii\rbac\DbManager::$checkAccessAssignments` is now `protected` (alex-code)
- Bug #18239: Fix support of no-extension files for `FileValidator::validateExtension()` (darkdef) - Bug #18239: Fix support of no-extension files for `FileValidator::validateExtension()` (darkdef)
- Bug #18229: Add flag for recognize SyBase databases on uses pdo_dblib (darkdef) - Bug #18229: Add flag for recognize SyBase databases on uses pdo_dblib (darkdef)

View File

@ -100,7 +100,11 @@ class DbManager extends BaseManager
* @var array auth item parent-child relationships (childName => list of parents) * @var array auth item parent-child relationships (childName => list of parents)
*/ */
protected $parents; protected $parents;
/**
* @var array user assignments (user id => Assignment[])
* @since `protected` since 2.0.38
*/
protected $checkAccessAssignments = [];
/** /**
* Initializes the application component. * Initializes the application component.
@ -115,18 +119,16 @@ class DbManager extends BaseManager
} }
} }
private $_checkAccessAssignments = [];
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function checkAccess($userId, $permissionName, $params = []) public function checkAccess($userId, $permissionName, $params = [])
{ {
if (isset($this->_checkAccessAssignments[(string) $userId])) { if (isset($this->checkAccessAssignments[(string) $userId])) {
$assignments = $this->_checkAccessAssignments[(string) $userId]; $assignments = $this->checkAccessAssignments[(string) $userId];
} else { } else {
$assignments = $this->getAssignments($userId); $assignments = $this->getAssignments($userId);
$this->_checkAccessAssignments[(string) $userId] = $assignments; $this->checkAccessAssignments[(string) $userId] = $assignments;
} }
if ($this->hasNoAssignments($assignments)) { if ($this->hasNoAssignments($assignments)) {
@ -857,7 +859,7 @@ class DbManager extends BaseManager
'created_at' => $assignment->createdAt, 'created_at' => $assignment->createdAt,
])->execute(); ])->execute();
unset($this->_checkAccessAssignments[(string) $userId]); unset($this->checkAccessAssignments[(string) $userId]);
return $assignment; return $assignment;
} }
@ -870,7 +872,7 @@ class DbManager extends BaseManager
return false; return false;
} }
unset($this->_checkAccessAssignments[(string) $userId]); unset($this->checkAccessAssignments[(string) $userId]);
return $this->db->createCommand() return $this->db->createCommand()
->delete($this->assignmentTable, ['user_id' => (string) $userId, 'item_name' => $role->name]) ->delete($this->assignmentTable, ['user_id' => (string) $userId, 'item_name' => $role->name])
->execute() > 0; ->execute() > 0;
@ -885,7 +887,7 @@ class DbManager extends BaseManager
return false; return false;
} }
unset($this->_checkAccessAssignments[(string) $userId]); unset($this->checkAccessAssignments[(string) $userId]);
return $this->db->createCommand() return $this->db->createCommand()
->delete($this->assignmentTable, ['user_id' => (string) $userId]) ->delete($this->assignmentTable, ['user_id' => (string) $userId])
->execute() > 0; ->execute() > 0;
@ -970,7 +972,7 @@ class DbManager extends BaseManager
*/ */
public function removeAllAssignments() public function removeAllAssignments()
{ {
$this->_checkAccessAssignments = []; $this->checkAccessAssignments = [];
$this->db->createCommand()->delete($this->assignmentTable)->execute(); $this->db->createCommand()->delete($this->assignmentTable)->execute();
} }
@ -982,7 +984,7 @@ class DbManager extends BaseManager
$this->rules = null; $this->rules = null;
$this->parents = null; $this->parents = null;
} }
$this->_checkAccessAssignments = []; $this->checkAccessAssignments = [];
} }
public function loadFromCache() public function loadFromCache()