Completed
Push — master ( 9ed145...8e4a93 )
by vistart
04:04
created

MyController::actions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.me/
9
 * @copyright Copyright (c) 2016 - 2017 vistart
10
 * @license https://vistart.me/license/
11
 */
12
13
namespace rhosocial\organization\web\organization\controllers;
14
15
use rhosocial\user\UserProfileSearch;
16
use Yii;
17
use yii\filters\AccessControl;
18
use yii\filters\VerbFilter;
19
use yii\web\Controller;
20
use yii\web\UnauthorizedHttpException;
21
22
/**
23
 * @version 1.0
24
 * @author vistart <[email protected]>
25
 */
26
class MyController extends Controller
27
{
28
    public $layout = 'main';
29
30
    /**
31
     * @var string UseProfileSearch Class.
32
     */
33
    public $userProfileSearchClass = UserProfileSearch::class;
34
35
    public function actions()
36
    {
37
        return [
38
            'index' => [
39
                'class' => 'rhosocial\organization\web\organization\controllers\my\IndexAction',
40
            ],
41
            'set-up-organization' => [
42
                'class' => 'rhosocial\organization\web\organization\controllers\my\SetUpOrganizationAction',
43
            ],
44
            'set-up-department' => [
45
                'class' => 'rhosocial\organization\web\organization\controllers\my\SetUpDepartmentAction',
46
            ],
47
            'revoke' => [
48
                'class' => 'rhosocial\organization\web\organization\controllers\my\RevokeAction',
49
            ],
50
            'member' => [
51
                'class' => 'rhosocial\organization\web\organization\controllers\my\MemberAction',
52
            ],
53
            'add-member' => [
54
                'class' => 'rhosocial\organization\web\organization\controllers\my\AddMemberAction',
55
            ],
56
            'update-member' => [
57
                'class' => 'rhosocial\organization\web\organization\controllers\my\UpdateMemberAction',
58
            ],
59
            'remove-member' => [
60
                'class' => 'rhosocial\organization\web\organization\controllers\my\RemoveMemberAction',
61
            ],
62
        ];
63
    }
64
65
    public function behaviors()
66
    {
67
        return [
68
            'access' => [
69
                'class' => AccessControl::class,
70
                'rules' => [
71
                    [
72
                        'allow' => false,
73
                        'roles' => ['?'],
74
                    ],
75
                    [ // Disallow user who does not have `setUpOrganization` permission to access this `set-up-organization` action.
76
                        'actions' => ['set-up-organization'],
77
                        'allow' => false,
78
                        'matchCallback' => function ($rule, $action) {
0 ignored issues
show
Unused Code introduced by
The parameter $rule is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $action is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
                            return !Yii::$app->user->can('setUpOrganization');
80
                        },
81
                        'denyCallback' => function ($rule, $action) {
0 ignored issues
show
Unused Code introduced by
The parameter $rule is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $action is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
                            throw new UnauthorizedHttpException(Yii::t('organization', 'You do not have access to set up new organization.'));
83
                        },
84
                    ],
85
                    [
86
                        'allow' => true,
87
                        'roles' => ['@'],
88
                    ]
89
                ],
90
            ],
91
            'verbs' => [
92
                'class' => VerbFilter::class,
93
                'actions' => [
94
                    'revoke' => ['post'],
95
                    'remove-member' => ['post'],
96
                ]
97
            ],
98
        ];
99
    }
100
}
101