Completed
Push — master ( 98ec57...b39146 )
by Andrii
02:05
created

RbacController::actionShow()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 23
ccs 0
cts 20
cp 0
rs 8.7972
cc 4
eloc 15
nc 8
nop 0
crap 20
1
<?php
2
/**
3
 * RBAC implementation for HiPanel.
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-rbac
6
 * @package   hipanel-rbac
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\rbac\console;
12
13
use hipanel\rbac\Initer;
14
use Yii;
15
16
/**
17
 * Class RbacController.
18
 *
19
 * Usage: `hidev rbac/init`
20
 */
21
class RbacController extends \yii\console\Controller
22
{
23
    public $defaultAction = 'show';
24
25
    public function actionInit()
26
    {
27
        $auth = Yii::$app->get('authManager');
28
        Initer::init($auth);
29
    }
30
31
    public function actionReinit()
32
    {
33
        $auth = Yii::$app->get('authManager');
34
        Initer::reinit($auth);
35
    }
36
37
    public function actionShow()
38
    {
39
        $auth = Yii::$app->get('authManager');
40
41
        echo "Permissions:\n";
42
        $permissions = $auth->getPermissions();
43
        ksort($permissions);
44
        foreach ($permissions as $name => $perm) {
45
            echo "   $perm->name $perm->description\n";
46
        }
47
48
        echo "Roles:\n";
49
        foreach ($auth->getRoles() as $name => $role) {
50
            $children = implode(',', array_keys($auth->getChildren($name)));
51
            printf("   %-12s %s\n", "$role->name:", $children);
52
        }
53
54
        echo "Assignments:\n";
55
        foreach ($auth->getAllAssignments() as $userId => $roles) {
56
            $roles = implode(',', array_keys($roles));
57
            printf("   %-12s %s\n", "$userId:", $roles);
58
        }
59
    }
60
}
61