Create ImportPolicy
MODIFY
app/Http/Controllers/ImportController.php
app/Http/Controllers/ImportController.php
@@ -37,7 +37,7 @@ class ImportController extends Controller {
}
public function getPrepare(Import $import) {
- // TODO AUTHORIZE
+ $this->authorize('modify', $import);
$headers = [];
@@ -55,7 +55,7 @@ class ImportController extends Controller {
}
public function postPrepare(Request $request, Import $import) {
- // TODO AUTHORIZE
+ $this->authorize('modify', $import);
// TODO VALIDATE
@@ -70,7 +70,7 @@ class ImportController extends Controller {
}
public function getComplete(Import $import) {
- // TODO AUTHORIZE
+ $this->authorize('modify', $import);
$file = fopen(storage_path('app/imports/' . $import->file), 'r');
@@ -93,7 +93,7 @@ class ImportController extends Controller {
}
public function postComplete(Request $request, Import $import) {
- // TODO AUTHORIZE
+ $this->authorize('modify', $import);
// TODO VALIDATE

ADD
app/Policies/ImportPolicy.php
+<?php
+
+namespace App\Policies;
+
+use App\Import;
+use App\User;
+
+class ImportPolicy {
+ public function modify(User $user, Import $import) {
+ return $user->spaces->contains($import->space_id);
+ }
+}

MODIFY
app/Providers/AuthServiceProvider.php
app/Providers/AuthServiceProvider.php
namespace App\Providers;
+use App\Import;
+use App\Policies\ImportPolicy;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use App\Policies\RecurringPolicy;
@@ -19,7 +21,8 @@ class AuthServiceProvider extends ServiceProvider
'App\Earning' => 'App\Policies\EarningPolicy',
'App\Spending' => 'App\Policies\SpendingPolicy',
Recurring::class => RecurringPolicy::class,
- 'App\Tag' => 'App\Policies\TagPolicy'
+ 'App\Tag' => 'App\Policies\TagPolicy',
+ Import::class => ImportPolicy::class
];
/**

Create ImportPolicy