mdmsoft / yii2-admin

Auth manager for Yii2 (RBAC Manager)
GNU General Public License v3.0
1.16k stars 574 forks source link

Grand Access not display permissions #164

Open iomakarov opened 9 years ago

iomakarov commented 9 years ago

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]);

gauravparashar12 commented 9 years ago

@iomakarov We are also getting same issue. Please suggest solution to it if you get resolve this issue till now.

iomakarov commented 9 years ago

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.

mdmunir commented 9 years ago

https://github.com/mdmsoft/yii2-admin/issues/167#issuecomment-108756450