Fix the PIREP edit permissions
This commit is contained in:
@@ -431,13 +431,16 @@ class PirepController extends Controller
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
/** @var Pirep $pirep */
|
||||
$pirep = $this->pirepRepo->findWithoutFail($id);
|
||||
if (empty($pirep)) {
|
||||
Flash::error('Pirep not found');
|
||||
return redirect(route('frontend.pireps.index'));
|
||||
}
|
||||
|
||||
if ($pirep->user_id !== Auth::id()) {
|
||||
throw new Unauthorized(new Exception('You may not edit the PIREP of other users'));
|
||||
Flash::error('Cannot edit someone else\'s PIREP!');
|
||||
return redirect(route('admin.pireps.index'));
|
||||
}
|
||||
|
||||
// Eager load the subfleet and fares under it
|
||||
@@ -492,12 +495,21 @@ class PirepController extends Controller
|
||||
*/
|
||||
public function update($id, UpdatePirepRequest $request)
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
/** @var Pirep $pirep */
|
||||
$pirep = $this->pirepRepo->findWithoutFail($id);
|
||||
if (empty($pirep)) {
|
||||
Flash::error('Pirep not found');
|
||||
return redirect(route('admin.pireps.index'));
|
||||
}
|
||||
|
||||
if ($user->id !== $pirep->user_id) {
|
||||
Flash::error('Cannot edit someone else\'s PIREP!');
|
||||
return redirect(route('admin.pireps.index'));
|
||||
}
|
||||
|
||||
$orig_route = $pirep->route;
|
||||
$attrs = $request->all();
|
||||
$attrs['submit'] = strtolower($attrs['submit']);
|
||||
@@ -549,8 +561,10 @@ class PirepController extends Controller
|
||||
Flash::error('PIREP not found');
|
||||
return redirect(route('admin.pireps.index'));
|
||||
}
|
||||
|
||||
if ($pirep->user_id !== Auth::id()) {
|
||||
throw new Unauthorized(new Exception('You may not submit the PIREP of other users'));
|
||||
Flash::error('Cannot edit someone else\'s PIREP!');
|
||||
return redirect(route('admin.pireps.index'));
|
||||
}
|
||||
|
||||
$this->pirepSvc->submit($pirep);
|
||||
|
||||
Reference in New Issue
Block a user