1 | <?php |
||||
2 | |||||
3 | namespace app\traits; |
||||
4 | |||||
5 | use Yii; |
||||
6 | |||||
7 | /** |
||||
8 | * Class AccessTrait |
||||
9 | * |
||||
10 | * @package app\traits |
||||
11 | */ |
||||
12 | trait AccessTrait |
||||
13 | { |
||||
14 | /** |
||||
15 | * @var bool |
||||
16 | */ |
||||
17 | protected $check_access = true; |
||||
18 | |||||
19 | /** |
||||
20 | * @return bool |
||||
21 | */ |
||||
22 | protected function checkAccessToAdministrate() |
||||
23 | { |
||||
24 | if (!$this->check_access) { |
||||
25 | return true; |
||||
26 | } |
||||
27 | |||||
28 | if (Yii::$app->user->can('VIEW_BACKSIDE') |
||||
0 ignored issues
–
show
|
|||||
29 | && Yii::$app->user->can('CREATE') |
||||
30 | && Yii::$app->user->can('UPDATE') |
||||
31 | && Yii::$app->user->can('DELETE') |
||||
32 | && Yii::$app->user->can('SET_ROLES')) { |
||||
33 | return true; |
||||
34 | } |
||||
35 | |||||
36 | return false; |
||||
37 | } |
||||
38 | |||||
39 | /** |
||||
40 | * @return bool |
||||
41 | */ |
||||
42 | protected function checkAccessToIndex() |
||||
43 | { |
||||
44 | if (!$this->check_access) { |
||||
45 | return true; |
||||
46 | } |
||||
47 | |||||
48 | if (Yii::$app->user->can('VIEW_BACKSIDE')) { |
||||
49 | return true; |
||||
50 | } |
||||
51 | |||||
52 | return false; |
||||
53 | } |
||||
54 | |||||
55 | /** |
||||
56 | * @return bool |
||||
57 | */ |
||||
58 | protected function checkAccessToView() |
||||
59 | { |
||||
60 | if (!$this->check_access) { |
||||
61 | return true; |
||||
62 | } |
||||
63 | |||||
64 | if (Yii::$app->user->can('VIEW_BACKSIDE')) { |
||||
65 | return true; |
||||
66 | } |
||||
67 | |||||
68 | return false; |
||||
69 | } |
||||
70 | |||||
71 | /** |
||||
72 | * @return bool |
||||
73 | */ |
||||
74 | protected function checkAccessToCreate() |
||||
75 | { |
||||
76 | if (!$this->check_access) { |
||||
77 | return true; |
||||
78 | } |
||||
79 | |||||
80 | if (Yii::$app->user->can('CREATE')) { |
||||
81 | return true; |
||||
82 | } |
||||
83 | |||||
84 | return false; |
||||
85 | } |
||||
86 | |||||
87 | /** |
||||
88 | * @return bool |
||||
89 | */ |
||||
90 | protected function checkAccessToUpdate() |
||||
91 | { |
||||
92 | if (!$this->check_access) { |
||||
93 | return true; |
||||
94 | } |
||||
95 | |||||
96 | if (Yii::$app->user->can('UPDATE')) { |
||||
97 | return true; |
||||
98 | } |
||||
99 | |||||
100 | return false; |
||||
101 | } |
||||
102 | |||||
103 | /** |
||||
104 | * @return bool |
||||
105 | */ |
||||
106 | protected function checkAccessToDelete() |
||||
107 | { |
||||
108 | if (!$this->check_access) { |
||||
109 | return true; |
||||
110 | } |
||||
111 | |||||
112 | if (Yii::$app->user->can('DELETE')) { |
||||
113 | return true; |
||||
114 | } |
||||
115 | |||||
116 | return false; |
||||
117 | } |
||||
118 | |||||
119 | /** |
||||
120 | * @return bool |
||||
121 | */ |
||||
122 | protected function checkAccessToSetRoles() |
||||
123 | { |
||||
124 | if (!$this->check_access) { |
||||
125 | return true; |
||||
126 | } |
||||
127 | |||||
128 | if (Yii::$app->user->can('SET_ROLES')) { |
||||
129 | return true; |
||||
130 | } |
||||
131 | |||||
132 | return false; |
||||
133 | } |
||||
134 | |||||
135 | /** |
||||
136 | * @param string $message |
||||
137 | * |
||||
138 | * @return mixed |
||||
139 | */ |
||||
140 | protected function accessError(string $message = '') |
||||
141 | { |
||||
142 | return $this->render('@app/views/admin/errors/access_error', [ |
||||
0 ignored issues
–
show
It seems like
render() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
143 | 'message' => !empty($message) ? $message : Yii::t('app', 'You do not have any permissions to perform this action.') |
||||
144 | ]); |
||||
145 | } |
||||
146 | } |
||||
147 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.