1 | <?php |
||
28 | class Permission |
||
29 | { |
||
30 | /** |
||
31 | * The Guard implementation. |
||
32 | * |
||
33 | * @var Guard |
||
34 | */ |
||
35 | protected $auth; |
||
36 | |||
37 | /** |
||
38 | * List of permissions that can be accessed by public users. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $publicAccess = [ |
||
43 | 'issue-view', |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * Ordered list of contexts. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $contexts = [ |
||
52 | 'comment', |
||
53 | 'attachment', |
||
54 | 'issue', |
||
55 | 'project', |
||
56 | ]; |
||
57 | |||
58 | /** |
||
59 | * Create a new filter instance. |
||
60 | * |
||
61 | * @param Guard $auth |
||
62 | */ |
||
63 | 45 | public function __construct(Guard $auth) |
|
67 | |||
68 | /** |
||
69 | * Handle an incoming request. |
||
70 | * |
||
71 | * @param Request $request |
||
72 | * @param \Closure $next |
||
73 | * |
||
74 | * @return mixed |
||
75 | */ |
||
76 | 44 | public function handle(Request $request, Closure $next) |
|
87 | |||
88 | /** |
||
89 | * Whether or not the current context is in public project. |
||
90 | * |
||
91 | * @param Request $request |
||
92 | * @param string $permission |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | 44 | protected function isInPublicProjectContext(Request $request, $permission) |
|
106 | |||
107 | /** |
||
108 | * Whether or not the user can access the current context. |
||
109 | * |
||
110 | * @param Request $request |
||
111 | * @param string $permission |
||
112 | * |
||
113 | * @return bool |
||
114 | */ |
||
115 | 44 | protected function canAccess(Request $request, $permission) |
|
121 | |||
122 | /** |
||
123 | * Whether or not the user has a valid permission in current context |
||
124 | * e.g. can access the issue or the project. |
||
125 | * |
||
126 | * @param User $user |
||
127 | * @param Route $route |
||
128 | * @param string $permission |
||
129 | * |
||
130 | * @return bool |
||
131 | */ |
||
132 | 41 | public function canAccessContext(User $user, Route $route, $permission) |
|
145 | |||
146 | /** |
||
147 | * Return the model object of the current context. |
||
148 | * We check the lowest ( Comment ) first, to the highest ( Project ). |
||
149 | * |
||
150 | * @param Route $route |
||
151 | * |
||
152 | * @return ModelAbstract |
||
153 | */ |
||
154 | 10 | protected function getCurrentContext(Route $route) |
|
165 | |||
166 | /** |
||
167 | * Returns the permission defined in route action. |
||
168 | * |
||
169 | * @param Request $request |
||
170 | * |
||
171 | * @return mixed |
||
172 | */ |
||
173 | 44 | protected function getPermission(Request $request) |
|
179 | } |
||
180 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.