Skip to content

Commit

Permalink
Fix #18196: yii\rbac\DbManager::$checkAccessAssignments is now `pro…
Browse files Browse the repository at this point in the history
…tected`
  • Loading branch information
alex-code authored Sep 8, 2020
1 parent 6342ad8 commit 9141cc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- Bug #18248: Render only one stack trace on console for chained exceptions (mikehaertl)
- 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 #18229: Add flag for recognize SyBase databases on uses pdo_dblib (darkdef)

Expand Down
24 changes: 13 additions & 11 deletions rbac/DbManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ class DbManager extends BaseManager
* @var array auth item parent-child relationships (childName => list of parents)
*/
protected $parents;

/**
* @var array user assignments (user id => Assignment[])
* @since `protected` since 2.0.38
*/
protected $checkAccessAssignments = [];

/**
* Initializes the application component.
Expand All @@ -115,18 +119,16 @@ public function init()
}
}

private $_checkAccessAssignments = [];

/**
* {@inheritdoc}
*/
public function checkAccess($userId, $permissionName, $params = [])
{
if (isset($this->_checkAccessAssignments[(string) $userId])) {
$assignments = $this->_checkAccessAssignments[(string) $userId];
if (isset($this->checkAccessAssignments[(string) $userId])) {
$assignments = $this->checkAccessAssignments[(string) $userId];
} else {
$assignments = $this->getAssignments($userId);
$this->_checkAccessAssignments[(string) $userId] = $assignments;
$this->checkAccessAssignments[(string) $userId] = $assignments;
}

if ($this->hasNoAssignments($assignments)) {
Expand Down Expand Up @@ -857,7 +859,7 @@ public function assign($role, $userId)
'created_at' => $assignment->createdAt,
])->execute();

unset($this->_checkAccessAssignments[(string) $userId]);
unset($this->checkAccessAssignments[(string) $userId]);
return $assignment;
}

Expand All @@ -870,7 +872,7 @@ public function revoke($role, $userId)
return false;
}

unset($this->_checkAccessAssignments[(string) $userId]);
unset($this->checkAccessAssignments[(string) $userId]);
return $this->db->createCommand()
->delete($this->assignmentTable, ['user_id' => (string) $userId, 'item_name' => $role->name])
->execute() > 0;
Expand All @@ -885,7 +887,7 @@ public function revokeAll($userId)
return false;
}

unset($this->_checkAccessAssignments[(string) $userId]);
unset($this->checkAccessAssignments[(string) $userId]);
return $this->db->createCommand()
->delete($this->assignmentTable, ['user_id' => (string) $userId])
->execute() > 0;
Expand Down Expand Up @@ -970,7 +972,7 @@ public function removeAllRules()
*/
public function removeAllAssignments()
{
$this->_checkAccessAssignments = [];
$this->checkAccessAssignments = [];
$this->db->createCommand()->delete($this->assignmentTable)->execute();
}

Expand All @@ -982,7 +984,7 @@ public function invalidateCache()
$this->rules = null;
$this->parents = null;
}
$this->_checkAccessAssignments = [];
$this->checkAccessAssignments = [];
}

public function loadFromCache()
Expand Down

0 comments on commit 9141cc5

Please sign in to comment.