Skip to content

Commit c881727

Browse files
committed
Add redirect for missing template
1 parent ee00699 commit c881727

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

app/Http/Controllers/ReportTemplatesController.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use App\Models\CustomField;
66
use App\Models\ReportTemplate;
7-
use Illuminate\Contracts\View\View;
87
use Illuminate\Http\RedirectResponse;
98
use Illuminate\Http\Request;
109

@@ -47,13 +46,20 @@ public function show($reportId)
4746
]);
4847
}
4948

50-
public function edit($reportId): View
49+
public function edit($reportId)
5150
{
5251
$this->authorize('reports.view');
5352

53+
$reportTemplate = ReportTemplate::find($reportId);
54+
55+
if (!$reportTemplate) {
56+
return redirect()->route('reports/custom')
57+
->with('error', trans('admin/reports/message.no_report_permission'));
58+
}
59+
5460
return view('reports/custom', [
5561
'customfields' => CustomField::get(),
56-
'template' => ReportTemplate::findOrFail($reportId),
62+
'template' => $reportTemplate,
5763
]);
5864
}
5965

tests/Feature/ReportTemplates/EditReportTemplateTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public function testRequiresPermission()
1818

1919
public function testCannotLoadEditPageForAnotherUsersReportTemplate()
2020
{
21-
$this->markTestIncomplete('Returns 404...');
22-
2321
$user = User::factory()->canViewReports()->create();
2422
$reportTemplate = ReportTemplate::factory()->create();
2523

0 commit comments

Comments
 (0)