From c1bc5a66772e70e3635477d82b0f32fed6588d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 29 Jul 2018 17:32:45 +0200 Subject: [PATCH] auth for table conf page --- app/Http/Controllers/TableController.php | 4 ++- app/Policies/TablePolicy.php | 26 +++++++++++++++++++ app/Providers/AuthServiceProvider.php | 2 +- .../table/{edit.blade.php => conf.blade.php} | 0 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 app/Policies/TablePolicy.php rename resources/views/table/{edit.blade.php => conf.blade.php} (100%) diff --git a/app/Http/Controllers/TableController.php b/app/Http/Controllers/TableController.php index 35c77f4..6b04aba 100644 --- a/app/Http/Controllers/TableController.php +++ b/app/Http/Controllers/TableController.php @@ -72,7 +72,9 @@ class TableController extends Controller $tableModel = $user->tables()->where('name', $table)->first(); if ($tableModel === null) abort(404, "No such table."); - return view('table.edit', [ + $this->authorize('edit', $tableModel); + + return view('table.conf', [ 'table' => $tableModel, ]); } diff --git a/app/Policies/TablePolicy.php b/app/Policies/TablePolicy.php new file mode 100644 index 0000000..f1d493e --- /dev/null +++ b/app/Policies/TablePolicy.php @@ -0,0 +1,26 @@ +ownsTable($table); + } + + public function delete(User $user, Table $table) + { + return $user->ownsTable($table); + } +} diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 9784b1a..a1084a6 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -13,7 +13,7 @@ class AuthServiceProvider extends ServiceProvider * @var array */ protected $policies = [ - 'App\Model' => 'App\Policies\ModelPolicy', + \App\Models\Table::class => \App\Policies\TablePolicy::class, ]; /** diff --git a/resources/views/table/edit.blade.php b/resources/views/table/conf.blade.php similarity index 100% rename from resources/views/table/edit.blade.php rename to resources/views/table/conf.blade.php