Add authorization to saving saved reports route

This commit is contained in:
Marcus Moore 2023-12-11 15:34:17 -08:00
parent c3845f4393
commit 52028ddef2
No known key found for this signature in database
3 changed files with 21 additions and 0 deletions

View file

@ -8,6 +8,8 @@ class SavedReportsController extends Controller
{
public function store(Request $request)
{
$this->authorize('reports.view');
$report = $request->user()->savedReports()->create([
'name' => $request->get('report_name'),
'options' => $request->except(['_token', 'report_name']),

View file

@ -357,6 +357,7 @@ Route::group(['middleware' => ['auth']], function () {
)->name('reports/export/accessories');
Route::get('reports/custom', [ReportsController::class, 'getCustomReport'])->name('reports/custom');
Route::post('reports/custom', [ReportsController::class, 'postCustom']);
// @todo: change to saved-template?
Route::post('reports/savedtemplate', [SavedReportsController::class, 'store'])->name('savedreports/store');
Route::get(

View file

@ -49,4 +49,22 @@ class SavedReportsTest extends TestCase
{
$this->markTestIncomplete();
}
public function testSavingReportRequiresValidFields()
{
$this->markTestIncomplete();
$this->actingAs(User::factory()->canViewReports()->create())
->post(route('savedreports/store'), [
//
])
->assertSessionHasErrors('report_name');
}
public function testSavingReportRequiresCorrectPermission()
{
$this->actingAs(User::factory()->create())
->post(route('savedreports/store'))
->assertForbidden();
}
}