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\organization\exceptions\NumberOfOrganizationsExceededException; |
16
|
|
|
use rhosocial\user\UserProfileSearch; |
17
|
|
|
use Yii; |
18
|
|
|
use yii\filters\AccessControl; |
19
|
|
|
use yii\filters\VerbFilter; |
20
|
|
|
use yii\web\Controller; |
21
|
|
|
use yii\web\UnauthorizedHttpException; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @version 1.0 |
25
|
|
|
* @author vistart <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class MyController extends Controller |
28
|
|
|
{ |
29
|
|
|
public $layout = 'main'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @inheritdoc |
33
|
|
|
*/ |
34
|
|
|
public function actions() |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
'index' => [ |
38
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\IndexAction', |
39
|
|
|
], |
40
|
|
|
'set-up-organization' => [ |
41
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\SetUpOrganizationAction', |
42
|
|
|
], |
43
|
|
|
'set-up-department' => [ |
44
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\SetUpDepartmentAction', |
45
|
|
|
], |
46
|
|
|
'update' => [ |
47
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\UpdateAction', |
48
|
|
|
], |
49
|
|
|
'revoke' => [ |
50
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\RevokeAction', |
51
|
|
|
], |
52
|
|
|
'member' => [ |
53
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\MemberAction', |
54
|
|
|
], |
55
|
|
|
'add-member' => [ |
56
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\AddMemberAction', |
57
|
|
|
], |
58
|
|
|
'update-member' => [ |
59
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\UpdateMemberAction', |
60
|
|
|
], |
61
|
|
|
'remove-member' => [ |
62
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\RemoveMemberAction', |
63
|
|
|
], |
64
|
|
|
'assign-admin' => [ |
65
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\AssignAdminAction', |
66
|
|
|
], |
67
|
|
|
'settings' => [ |
68
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\SettingsAction', |
69
|
|
|
], |
70
|
|
|
'exit' => [ |
71
|
|
|
'class' => 'rhosocial\organization\web\organization\controllers\my\ExitAction', |
72
|
|
|
], |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @inheritdoc |
78
|
|
|
*/ |
79
|
|
|
public function behaviors() |
80
|
|
|
{ |
81
|
|
|
return [ |
82
|
|
|
'access' => [ |
83
|
|
|
'class' => AccessControl::class, |
84
|
|
|
'rules' => [ |
85
|
|
|
[ |
86
|
|
|
'allow' => false, |
87
|
|
|
'roles' => ['?'], |
88
|
|
|
], |
89
|
|
|
[ // Disallow user who does not have `setUpOrganization` permission to access this `set-up-organization` action. |
90
|
|
|
'actions' => ['set-up-organization'], |
91
|
|
|
'allow' => false, |
92
|
|
|
'matchCallback' => function ($rule, $action) { |
|
|
|
|
93
|
|
|
return !Yii::$app->user->can('setUpOrganization'); |
94
|
|
|
}, |
95
|
|
|
'denyCallback' => function ($rule, $action) { |
|
|
|
|
96
|
|
|
if (Yii::$app->user->identity->hasReachedOrganizationLimit()) { |
97
|
|
|
throw new NumberOfOrganizationsExceededException(); |
98
|
|
|
} |
99
|
|
|
throw new UnauthorizedHttpException(Yii::t('organization', 'You do not have access to set up new organization.')); |
100
|
|
|
}, |
101
|
|
|
], |
102
|
|
|
[ |
103
|
|
|
'allow' => true, |
104
|
|
|
'roles' => ['@'], |
105
|
|
|
], |
106
|
|
|
], |
107
|
|
|
], |
108
|
|
|
'verbs' => [ |
109
|
|
|
'class' => VerbFilter::class, |
110
|
|
|
'actions' => [ |
111
|
|
|
'revoke' => ['post'], |
112
|
|
|
'remove-member' => ['post'], |
113
|
|
|
'assign-admin' => ['post'], |
114
|
|
|
'exit' => ['post'], |
115
|
|
|
] |
116
|
|
|
], |
117
|
|
|
]; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param $id |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function actionView($id) |
|
|
|
|
125
|
|
|
{ |
126
|
|
|
return $this->render('view'); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.