mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Fixes for schedule form validation
This commit is contained in:
parent
a25a90d3d1
commit
56e83f6e6c
@ -37,6 +37,7 @@ use App\Models\Scheduler;
|
||||
use App\Utils\Ninja;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class TaskSchedulerService
|
||||
@ -83,110 +84,91 @@ class TaskSchedulerService
|
||||
|
||||
}
|
||||
|
||||
private function runValidation($form_request, $data)
|
||||
{
|
||||
$_syn_request_class = new $form_request();
|
||||
$_syn_request_class->setContainer(app());
|
||||
$_syn_request_class->initialize($data);
|
||||
$_syn_request_class->prepareForValidation();
|
||||
$_syn_request_class->setValidator(Validator::make($_syn_request_class->all(), $_syn_request_class->rules()));
|
||||
|
||||
return $_syn_request_class->validated();
|
||||
}
|
||||
|
||||
public function setJobParameters(ScheduledJob $job, $request): ScheduledJob
|
||||
{
|
||||
switch ($request->job) {
|
||||
case ScheduledJob::CREATE_CLIENT_REPORT:
|
||||
$rules = (new GenericReportRequest)->rules();
|
||||
//custom rules for example here we require date_range but in genericRequest class we don't
|
||||
$rules['date_range'] = 'string|required';
|
||||
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_CLIENT_REPORT;
|
||||
$job->action_class = $this->getClassPath(ClientExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_CLIENT_CONTACT_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
|
||||
$job->action_name = ScheduledJob::CREATE_CLIENT_CONTACT_REPORT;
|
||||
$job->action_class = $this->getClassPath(ContactExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_CREDIT_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
|
||||
$job->action_name = ScheduledJob::CREATE_CREDIT_REPORT;
|
||||
$job->action_class = $this->getClassPath(CreditExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_DOCUMENT_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_DOCUMENT_REPORT;
|
||||
$job->action_class = $this->getClassPath(DocumentExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_EXPENSE_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_EXPENSE_REPORT;
|
||||
$job->action_class = $this->getClassPath(ExpenseExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_INVOICE_ITEM_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_INVOICE_ITEM_REPORT;
|
||||
$job->action_class = $this->getClassPath(InvoiceItemExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_INVOICE_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_INVOICE_REPORT;
|
||||
$job->action_class = $this->getClassPath(InvoiceExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_PAYMENT_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_PAYMENT_REPORT;
|
||||
$job->action_class = $this->getClassPath(PaymentExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_PRODUCT_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_PRODUCT_REPORT;
|
||||
$job->action_class = $this->getClassPath(ProductExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_PROFIT_AND_LOSS_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_PROFIT_AND_LOSS_REPORT;
|
||||
$job->action_class = $this->getClassPath(ProfitAndLoss::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_QUOTE_ITEM_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_QUOTE_ITEM_REPORT;
|
||||
$job->action_class = $this->getClassPath(QuoteItemExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_QUOTE_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_QUOTE_REPORT;
|
||||
$job->action_class = $this->getClassPath(QuoteExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_RECURRING_INVOICE_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_RECURRING_INVOICE_REPORT;
|
||||
$job->action_class = $this->getClassPath(RecurringInvoiceExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
case ScheduledJob::CREATE_TASK_REPORT:
|
||||
$validator = GenericReportRequest::runFormRequest($request->all());
|
||||
$validatedJobData = $validator->validate();
|
||||
$job->action_name = ScheduledJob::CREATE_TASK_REPORT;
|
||||
$job->action_class = $this->getClassPath(TaskExport::class);
|
||||
$job->parameters = $validatedJobData;
|
||||
$job->parameters = $this->runValidation(GenericReportRequest::class, $request->all());
|
||||
break;
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ trait PageNumbering
|
||||
private function pageNumbering($pdf_data_object, $company)
|
||||
{
|
||||
|
||||
if(!$company->settings->page_numbering)
|
||||
if(!property_exists($company->settings, 'page_numbering') || !$company->settings->page_numbering)
|
||||
return $pdf_data_object;
|
||||
|
||||
try
|
||||
|
@ -22,7 +22,7 @@ class SchedulerTest extends TestCase
|
||||
use MakesHash;
|
||||
use MockUnitData;
|
||||
use WithoutEvents;
|
||||
use RefreshDatabase;
|
||||
// use RefreshDatabase;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
@ -77,7 +77,6 @@ class SchedulerTest extends TestCase
|
||||
{
|
||||
$response = $this->createScheduler();
|
||||
|
||||
nlog($response);
|
||||
$arr = $response->json();
|
||||
$id = $arr['data']['id'];
|
||||
|
||||
@ -115,23 +114,6 @@ class SchedulerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
public function testSchedulerCanBeDeleted()
|
||||
{
|
||||
$response = $this->createScheduler();
|
||||
|
||||
$arr = $response->json();
|
||||
$id = $arr['data']['id'];
|
||||
|
||||
$scheduler = Scheduler::find($this->decodePrimaryKey($id));
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->delete('/api/v1/task_scheduler/' . $this->encodePrimaryKey($scheduler->id));
|
||||
|
||||
$this->assertEquals(0, Scheduler::count());
|
||||
|
||||
}
|
||||
|
||||
public function testSchedulerJobCanBeUpdated()
|
||||
{
|
||||
@ -161,23 +143,6 @@ class SchedulerTest extends TestCase
|
||||
$this->assertSame('create_credit_report', $arr['data']['job']['action_name']);
|
||||
}
|
||||
|
||||
public function testSchedulerCanBeCreated()
|
||||
{
|
||||
$response = $this->createScheduler();
|
||||
|
||||
$arr = $response->json();
|
||||
$id = $arr['data']['id'];
|
||||
|
||||
$scheduler = Scheduler::find($this->decodePrimaryKey($id));
|
||||
|
||||
$all_schedulers = Scheduler::count();
|
||||
|
||||
$this->assertSame(1, $all_schedulers);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
public function createScheduler()
|
||||
{
|
||||
$data = [
|
||||
|
Loading…
Reference in New Issue
Block a user