Open iomakarov opened 9 years ago
@iomakarov We are also getting same issue. Please suggest solution to it if you get resolve this issue till now.
My solution: main.php 'components' => [ 'authManager' => [ 'class' => 'common\component\FixDbManager', // or use 'yii\rbac\DbManager' ],
FixDbManager.php class FixDbManager extends \yii\rbac\DbManager {
/**
* @inheritdoc
*/
public function getRolesByUser($userId)
{
if (empty($userId)) {
return [];
}
$query = (new Query)->select('b.*')
->from(['a' => $this->assignmentTable, 'b' => $this->itemTable])
->where('{{a}}.[[item_name]]={{b}}.[[name]]')
->andWhere(['a.user_id' => (string) $userId])
/*->andWhere(['b.type' => Item::TYPE_ROLE])*/;
$roles = [];
foreach ($query->all($this->db) as $row) {
$roles[$row['name']] = $this->populateItem($row);
}
return $roles;
}
}
It's temporary plug... But, what to do then? It is necessary to adapt this module. Ideally, you want to create a new type of TYPE_PATH = 3 and create sql-script to update the old records from 2 to 3 ID.
mdm\admin\controllers\AssignmentController public function actionView($id) not correct for Yii2 2.0.4
foreach ($authManager->getRolesByUser($id) as $role) { $type = $role->type; $assigned[$type == Item::TYPE_ROLE ? 'Roles' : 'Permissions'][$role->name] = $role->name; }
yii\rbac\DbManager 2.0.4 public function getRolesByUser($userId)
$query = (new Query)->select('b.*') ->from(['a' => $this->assignmentTable, 'b' => $this->itemTable]) ->where('{{a}}.[[item_name]]={{b}}.[[name]]') ->andWhere(['a.user_id' => (string) $userId]) ->andWhere(['b.type' => Item::TYPE_ROLE]);