mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Add validation for saving reports
This commit is contained in:
parent
b9cda88363
commit
89c47c1879
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\SavedReport;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SavedReportsController extends Controller
|
||||
|
@ -10,9 +11,11 @@ class SavedReportsController extends Controller
|
|||
{
|
||||
$this->authorize('reports.view');
|
||||
|
||||
$request->validate((new SavedReport)->getRules());
|
||||
|
||||
$report = $request->user()->savedReports()->create([
|
||||
'name' => $request->get('report_name'),
|
||||
'options' => $request->except(['_token', 'report_name']),
|
||||
'name' => $request->get('name'),
|
||||
'options' => $request->except(['_token', 'name']),
|
||||
]);
|
||||
|
||||
return redirect()->route('reports/custom', ['report' => $report->id]);
|
||||
|
|
|
@ -4,10 +4,12 @@ namespace App\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
class SavedReport extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use ValidatingTrait;
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
|
@ -25,6 +27,10 @@ class SavedReport extends Model
|
|||
];
|
||||
|
||||
// @todo: add $rules
|
||||
protected $rules = [
|
||||
'name' => 'required|unique:saved_reports,name',
|
||||
'options' => 'array',
|
||||
];
|
||||
|
||||
//we will need a bit to catch and store the name of the report.
|
||||
//for now the blip above is creating the name, but can be confusing if multiple are made at once
|
||||
|
|
|
@ -375,7 +375,7 @@
|
|||
<form method="post" id="savetemplateform" action="{{ route("savedreports/store") }}">
|
||||
@csrf
|
||||
<input type="hidden" id="savetemplateform" name="options">
|
||||
<input type="text" id="report_name" name="report_name">
|
||||
<input type="text" id="name" name="name">
|
||||
{{-- this will be a box to name the report? --}}
|
||||
<button class = "btn btn-primary" style="width: 100%">
|
||||
{{ trans('admin/reports/general.save_template') }}
|
||||
|
@ -464,8 +464,8 @@
|
|||
|
||||
$('<input>').attr({
|
||||
type: 'hidden',
|
||||
name: 'report_name',
|
||||
value: $('#report_name').val(),
|
||||
name: 'name',
|
||||
value: $('#name').val(),
|
||||
}).appendTo(form);
|
||||
|
||||
form.attr('action', '/reports/savedtemplate').submit();
|
||||
|
|
|
@ -36,15 +36,6 @@ class SavedReportsTest extends TestCase
|
|||
}]);
|
||||
}
|
||||
|
||||
public function testCanOnlySeeOwnSavedCustomReports()
|
||||
{
|
||||
$this->markTestIncomplete('potentially...');
|
||||
|
||||
// create saved reports for two users
|
||||
// load the route('reports/custom')
|
||||
// ensure the view only has the current users reports ($saved_reports)
|
||||
}
|
||||
|
||||
public function testCanSaveACustomReport()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
|
@ -52,13 +43,11 @@ class SavedReportsTest extends TestCase
|
|||
|
||||
public function testSavingReportRequiresValidFields()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
|
||||
$this->actingAs(User::factory()->canViewReports()->create())
|
||||
->post(route('savedreports/store'), [
|
||||
//
|
||||
])
|
||||
->assertSessionHasErrors('report_name');
|
||||
->assertSessionHasErrors('name');
|
||||
}
|
||||
|
||||
public function testSavingReportRequiresCorrectPermission()
|
||||
|
|
Loading…
Reference in a new issue