Skip to content

Commit

Permalink
improved rbac/show action
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Sep 27, 2016
1 parent b03792f commit 17d1714
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/console/RbacController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,42 @@
/**
* Class RbacController.
*
* Usage: ./hidev rbac/init
* Usage: `hidev rbac/init`
*/
class RbacController extends \yii\console\Controller
{
public function actionInit()
{
$auth = Yii::$app->get('authManager');
$auth->setAssignment('freezer', 'sol');

Initer::init($auth);
}

public function actionReinit()
{
$auth = Yii::$app->get('authManager');
Initer::reinit($auth);
}

public function actionShow()
{
$auth = Yii::$app->get('authManager');

echo "Permissions:\n";
foreach ($auth->getItems(Item::TYPE_PERMISSION) as $name => $perm) {
echo "\t$perm->name $perm->description\n";
foreach ($auth->getPermissions() as $name => $perm) {
echo " $perm->name $perm->description\n";
}

echo "Roles:\n";
foreach ($auth->getItems(Item::TYPE_ROLE) as $name => $role) {
foreach ($auth->getRoles() as $name => $role) {
$children = implode(',', array_keys($auth->getChildren($name)));
echo "\t$role->name [$children] $role->description\n";
printf(" %-12s %s\n", "$role->name:", $children);
}

echo "Assignments:\n";
foreach ($auth->getAllAssignments() as $userId => $roles) {
$roles = implode(',', array_keys($roles));
printf(" %-12s %s\n", "$userId:", $roles);
}
}

}

0 comments on commit 17d1714

Please sign in to comment.