From 4a766620ff328f8ba5e1c1b03677988b91ae2146 Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Thu, 16 Jul 2020 05:24:00 +0100 Subject: [PATCH] Fix appointment policy not being called correctly This commit fixes the appointment policy being called at the wrong time, with the wrong arguments. It also fixes wrong references on the auth service provider, also fixing other issues with poliy usage. Fixes #3 and SPACEJEWEL-HOSTING-59. --- app/Http/Controllers/AppointmentController.php | 4 +++- app/Providers/AuthServiceProvider.php | 16 +++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/AppointmentController.php b/app/Http/Controllers/AppointmentController.php index 662f2a0..1a97819 100644 --- a/app/Http/Controllers/AppointmentController.php +++ b/app/Http/Controllers/AppointmentController.php @@ -67,7 +67,6 @@ class AppointmentController extends Controller public function updateAppointment(Request $request, $applicationID, $status) { - $this->authorize('update', Appointment::class); $application = Application::find($applicationID); $validStatuses = [ @@ -75,6 +74,9 @@ class AppointmentController extends Controller 'CONCLUDED' ]; + $this->authorize('update', $application->appointment); + + if (!is_null($application)) { diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 7d3a4b8..52563b4 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -2,15 +2,15 @@ namespace App\Providers; -use App\Http\Controllers\BanController; -use App\Http\Controllers\VoteController; -use App\Http\Controllers\ProfileController; -use App\Http\Controllers\AppointmentController; use App\Policies\ProfilePolicy; use App\Policies\VacancyPolicy; use App\Policies\UserPolicy; +use App\Policies\BanPolicy; use App\Policies\FormPolicy; +use App\Policies\VotePolicy; use App\Policies\ApplicationPolicy; +use App\Policies\AppointmentPolicy; + use App\User; use App\Form; use App\Vote; @@ -18,6 +18,8 @@ use App\Vacancy; use App\Application; use App\Appointment; use App\Ban; + + use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Gate; @@ -36,9 +38,9 @@ class AuthServiceProvider extends ServiceProvider Vacancy::class => VacancyPolicy::class, //Form::class => FormPolicy::class 'App\Form' => 'App\Policies\FormPolicy', - Vote::class => VoteController::class, - Ban::class => BanController::class, - Appointment::class => AppointmentController::class + Vote::class => VotePolicy::class, + Ban::class => BanPolicy::class, + Appointment::class => AppointmentPolicy::class ]; /**