mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Fixed almost everything, but all functional tests are broken at the last minute :(
This commit is contained in:
38
api/rbac/Manager.php
Normal file
38
api/rbac/Manager.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace api\rbac;
|
||||
|
||||
use Yii;
|
||||
use yii\rbac\Assignment;
|
||||
use yii\rbac\PhpManager;
|
||||
|
||||
class Manager extends PhpManager {
|
||||
|
||||
/**
|
||||
* In our application the permissions are given not to users itself, but to tokens,
|
||||
* so we extract them from the extended identity interface.
|
||||
*
|
||||
* In Yii2, the mechanism of recursive permissions checking requires that the array
|
||||
* with permissions must be indexed by the keys of these permissions.
|
||||
*
|
||||
* @param string $accessToken
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAssignments($accessToken): array {
|
||||
$identity = Yii::$app->user->getIdentity();
|
||||
if ($identity === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$rawPermissions = $identity->getAssignedPermissions();
|
||||
$result = [];
|
||||
foreach ($rawPermissions as $name) {
|
||||
$result[$name] = new Assignment(['roleName' => $name]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user