Skip to content

Commit e5690be

Browse files
committed
add check for configured gate
1 parent 47c2aeb commit e5690be

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/ReactUpdateController.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Routing\Controller as BaseController;
1111
use Illuminate\Foundation\Validation\ValidatesRequests;
1212
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
13+
use Illuminate\Support\Facades\Gate;
1314

1415

1516
class ReactUpdateController extends BaseController
@@ -33,7 +34,12 @@ class ReactUpdateController extends BaseController
3334
*/
3435
public function __construct(ReactRequest $request){
3536
// TODO set up middleware that adapts to non-admin updates
36-
$this->middleware('can:admin-site');
37+
$gate_handle = config('react_sync.gate_handle');
38+
if(!Gate::has($gate_handle)){
39+
throw new \Exception("You must define a authorization rule named '$gate_handle' to protect access to the ReactUpdateController methods.");
40+
exit();
41+
}
42+
$this->middleware("can:$gate_handle");
3743

3844
}
3945

@@ -155,21 +161,19 @@ private function resolveBelongsTo($prop, $value){
155161

156162

157163
private function resolveHasMany($prop, $value){
158-
die('sdfsdfsdfsdf');
164+
throw new \Exception("Relationship 'resolveHasMany' is not yet enabled");
165+
die('Relationship not yet enabled');
159166
// Since this is a hasMany relationship, use the ...
160167
//
161168
// See documentation for mass assignment!! This has to be enabled on the model to which you are saving data.
162169
if(is_array($value)){ // always gonna be an array isn't it :(
163170
// Save all new relations
164-
dd($value);
165171
$this->model->{$prop}()->createMany($value);
166172
}
167173
else{
168174
$this->model->{$prop}()->create($value);
169175
}
170-
dd($this->model->{$prop});
171176
$this->model->{$prop}()->sync($value);
172-
dd($this->model);
173177
return $this->model;
174178
}
175179

src/config.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
*/
1313

1414
'global_variable_name' => env('REACT_SYNC_GLOBAL_VARIABLE_NAME', 'ReactSyncAppData'),
15+
16+
'gate_handle' => env('REACT_SYNC_GATE_HANDLE', 'admin-site'),
1517

1618
'api_path' => env('REACT_SYNC_API_PATH', '/update-state'),
1719

18-
'jsonable_controllers' => [
20+
'jsonable_controllers' => [
1921

20-
],
21-
22-
'jsonable_routes' => [
22+
],
23+
24+
'jsonable_routes' => [
2325

24-
],
26+
],
2527

2628
];

0 commit comments

Comments
 (0)