Fixes ACCOUNTS-5V9. Handle case when access token don't have associated account

This commit is contained in:
ErickSkrauch 2019-12-02 21:14:40 +03:00
parent a5f6a2d437
commit 22ef41ac7c

View File

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
namespace api\modules\oauth\controllers; namespace api\modules\oauth\controllers;
use api\controllers\Controller; use api\controllers\Controller;
@ -19,11 +21,23 @@ class IdentityController extends Controller {
'actions' => ['index'], 'actions' => ['index'],
'allow' => true, 'allow' => true,
'roles' => [P::OBTAIN_ACCOUNT_INFO], 'roles' => [P::OBTAIN_ACCOUNT_INFO],
'roleParams' => function() { 'roleParams' => function(): array {
/** @noinspection NullPointerExceptionInspection */ /** @var \api\components\User\IdentityInterface $identity */
return [ $identity = Yii::$app->user->getIdentity();
'accountId' => Yii::$app->user->getIdentity()->getAccount()->id, $account = $identity->getAccount();
]; if ($account === null) {
Yii::$app->sentry->captureMessage('Unexpected lack of account', [
'identityType' => get_class($identity),
'userId' => $identity->getId(),
'assignedPermissions' => $identity->getAssignedPermissions(),
], [
'level' => 'warning',
]);
return ['accountId' => 0];
}
return ['accountId' => $account->id];
}, },
], ],
], ],