File tree Expand file tree Collapse file tree 4 files changed +50
-4
lines changed Expand file tree Collapse file tree 4 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,17 @@ class DummyClass
1616 * @param \App\User $user
1717 * @return mixed
1818 */
19+ public function showEvery(User $user = null)
20+ {
21+ //
22+ }
23+
24+ /**
25+ * Determine whether the user is authorized to access the repository uriKey
26+ *
27+ * @param \App\User $user
28+ * @return mixed
29+ */
1930 public function showAny(User $user = null)
2031 {
2132 //
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ public function repository($key = null)
4444 }
4545
4646 if (! $ repository ::authorizedToShowAny ($ this )) {
47- throw new UnauthorizedException (__ ('Unauthorized to view repository :name. ' , [
47+ throw new UnauthorizedException (__ ('Unauthorized to view repository :name. See "showAny" policy. ' , [
4848 'name ' => $ repository ,
4949 ]), 403 );
5050 }
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ public function index(RestifyRequest $request)
4747 });
4848
4949 try {
50- $ this ->allowToViewAny ($ request , $ items );
50+ $ this ->allowToShowEvery ($ request , $ items );
5151 } catch (UnauthorizedException | AuthorizationException $ e ) {
5252 return $ this ->response ()->forbidden ()->addError ($ e ->getMessage ());
5353 }
@@ -203,9 +203,9 @@ public function allowToShow($request)
203203 * @param Collection $items
204204 * @throws \Illuminate\Auth\Access\AuthorizationException
205205 */
206- public function allowToViewAny ($ request , Collection $ items )
206+ public function allowToShowEvery ($ request , Collection $ items )
207207 {
208- $ this ->authorizeToShowAny ($ request );
208+ $ this ->authorizeToShowEvery ($ request );
209209 }
210210
211211 /**
Original file line number Diff line number Diff line change @@ -69,6 +69,41 @@ public static function authorizedToShowAny(Request $request)
6969 : true ;
7070 }
7171
72+ /**
73+ * Determine if the resource should be available for the given request (.
74+ *
75+ * @param \Illuminate\Http\Request $request
76+ * @return void
77+ * @throws AuthorizationException
78+ */
79+ public function authorizeToShowEvery (Request $ request )
80+ {
81+ if (! static ::authorizable ()) {
82+ return ;
83+ }
84+
85+ if (method_exists (Gate::getPolicyFor (static ::newModel ()), 'showEvery ' )) {
86+ $ this ->authorizeTo ($ request , 'showEvery ' );
87+ }
88+ }
89+
90+ /**
91+ * Determine if the resource should be available for the given request.
92+ *
93+ * @param \Illuminate\Http\Request $request
94+ * @return bool
95+ */
96+ public static function authorizedToShowEvery (Request $ request )
97+ {
98+ if (! static ::authorizable ()) {
99+ return true ;
100+ }
101+
102+ return method_exists (Gate::getPolicyFor (static ::newModel ()), 'showEvery ' )
103+ ? Gate::check ('showEvery ' , get_class (static ::newModel ()))
104+ : true ;
105+ }
106+
72107 /**
73108 * Determine if the current user can view the given resource or throw.
74109 *
You can’t perform that action at this time.
0 commit comments