mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 17:34:30 -04:00
Moving permissions to form requests
This commit is contained in:
parent
05bd8d9318
commit
2efd419791
@ -18,6 +18,10 @@ use App\Ninja\Repositories\TaskRepository;
|
|||||||
use App\Ninja\Repositories\InvoiceRepository;
|
use App\Ninja\Repositories\InvoiceRepository;
|
||||||
use App\Services\TaskService;
|
use App\Services\TaskService;
|
||||||
|
|
||||||
|
use App\Http\Requests\TaskRequest;
|
||||||
|
use App\Http\Requests\CreateTaskRequest;
|
||||||
|
use App\Http\Requests\UpdateTaskRequest;
|
||||||
|
|
||||||
class TaskController extends BaseController
|
class TaskController extends BaseController
|
||||||
{
|
{
|
||||||
protected $taskRepo;
|
protected $taskRepo;
|
||||||
@ -66,16 +70,16 @@ class TaskController extends BaseController
|
|||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function store()
|
public function store(CreateTaskRequest $request)
|
||||||
{
|
{
|
||||||
return $this->save();
|
return $this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($publicId)
|
public function show(TaskRequest $request)
|
||||||
{
|
{
|
||||||
Session::reflash();
|
Session::reflash();
|
||||||
|
|
||||||
return Redirect::to("tasks/{$publicId}/edit");
|
return Redirect::to("tasks/{$request->task_id}/edit");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,14 +87,13 @@ class TaskController extends BaseController
|
|||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function create($clientPublicId = 0)
|
public function create(TaskRequest $request)
|
||||||
{
|
{
|
||||||
$this->authorizeCreate();
|
|
||||||
$this->checkTimezone();
|
$this->checkTimezone();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'task' => null,
|
'task' => null,
|
||||||
'clientPublicId' => Input::old('client') ? Input::old('client') : ($clientPublicId ?: 0),
|
'clientPublicId' => Input::old('client') ? Input::old('client') : ($request->client_id ?: 0),
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'url' => 'tasks',
|
'url' => 'tasks',
|
||||||
'title' => trans('texts.new_task'),
|
'title' => trans('texts.new_task'),
|
||||||
@ -109,13 +112,11 @@ class TaskController extends BaseController
|
|||||||
* @param int $id
|
* @param int $id
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function edit($publicId)
|
public function edit(TaskRequest $request)
|
||||||
{
|
{
|
||||||
$this->checkTimezone();
|
$this->checkTimezone();
|
||||||
|
|
||||||
$task = Task::scope($publicId)->with('client', 'invoice')->withTrashed()->firstOrFail();
|
$task = $request->entity();
|
||||||
|
|
||||||
$this->authorize('edit', $task);
|
|
||||||
|
|
||||||
$actions = [];
|
$actions = [];
|
||||||
if ($task->invoice) {
|
if ($task->invoice) {
|
||||||
@ -143,7 +144,7 @@ class TaskController extends BaseController
|
|||||||
'task' => $task,
|
'task' => $task,
|
||||||
'clientPublicId' => $task->client ? $task->client->public_id : 0,
|
'clientPublicId' => $task->client ? $task->client->public_id : 0,
|
||||||
'method' => 'PUT',
|
'method' => 'PUT',
|
||||||
'url' => 'tasks/'.$publicId,
|
'url' => 'tasks/'.$task->public_id,
|
||||||
'title' => trans('texts.edit_task'),
|
'title' => trans('texts.edit_task'),
|
||||||
'duration' => $task->is_running ? $task->getCurrentDuration() : $task->getDuration(),
|
'duration' => $task->is_running ? $task->getCurrentDuration() : $task->getDuration(),
|
||||||
'actions' => $actions,
|
'actions' => $actions,
|
||||||
@ -163,9 +164,11 @@ class TaskController extends BaseController
|
|||||||
* @param int $id
|
* @param int $id
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function update($publicId)
|
public function update(UpdateTaskRequest $request)
|
||||||
{
|
{
|
||||||
return $this->save($publicId);
|
$task = $request->entity();
|
||||||
|
|
||||||
|
return $this->save($task->public_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getViewModel()
|
private static function getViewModel()
|
||||||
@ -180,20 +183,10 @@ class TaskController extends BaseController
|
|||||||
{
|
{
|
||||||
$action = Input::get('action');
|
$action = Input::get('action');
|
||||||
|
|
||||||
$this->authorizeUpdate(array('public_id'=>$publicId)/* Hacky, but works */);
|
|
||||||
|
|
||||||
if (in_array($action, ['archive', 'delete', 'restore'])) {
|
if (in_array($action, ['archive', 'delete', 'restore'])) {
|
||||||
return self::bulk();
|
return self::bulk();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($validator = $this->taskRepo->getErrors(Input::all())) {
|
|
||||||
$url = $publicId ? 'tasks/'.$publicId.'/edit' : 'tasks/create';
|
|
||||||
Session::flash('error', trans('texts.task_errors'));
|
|
||||||
return Redirect::to($url)
|
|
||||||
->withErrors($validator)
|
|
||||||
->withInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
$task = $this->taskRepo->save($publicId, Input::all());
|
$task = $this->taskRepo->save($publicId, Input::all());
|
||||||
Session::flash('message', trans($publicId ? 'texts.updated_task' : 'texts.created_task'));
|
Session::flash('message', trans($publicId ? 'texts.updated_task' : 'texts.created_task'));
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php namespace App\Http\Requests;
|
<?php namespace App\Http\Requests;
|
||||||
|
|
||||||
class CreateCreditRequest extends EntityRequest
|
class CreateCreditRequest extends CreditRequest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Determine if the user is authorized to make this request.
|
* Determine if the user is authorized to make this request.
|
||||||
|
26
app/Http/Requests/CreateTaskRequest.php
Normal file
26
app/Http/Requests/CreateTaskRequest.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php namespace App\Http\Requests;
|
||||||
|
|
||||||
|
class CreateTaskRequest extends TaskRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->can('create', ENTITY_TASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'time_log' => 'time_log',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
7
app/Http/Requests/CreditRequest.php
Normal file
7
app/Http/Requests/CreditRequest.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php namespace App\Http\Requests;
|
||||||
|
|
||||||
|
class CreditRequest extends EntityRequest {
|
||||||
|
|
||||||
|
protected $entityType = ENTITY_CREDIT;
|
||||||
|
|
||||||
|
}
|
18
app/Http/Requests/ExpenseRequest.php
Normal file
18
app/Http/Requests/ExpenseRequest.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php namespace App\Http\Requests;
|
||||||
|
|
||||||
|
class ExpenseRequest extends EntityRequest {
|
||||||
|
|
||||||
|
protected $entityType = ENTITY_EXPENSE;
|
||||||
|
|
||||||
|
public function entity()
|
||||||
|
{
|
||||||
|
$expense = parent::entity();
|
||||||
|
|
||||||
|
// eager load the contacts
|
||||||
|
if ($expense && ! count($expense->documents)) {
|
||||||
|
$expense->load('documents');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $expense;
|
||||||
|
}
|
||||||
|
}
|
7
app/Http/Requests/PaymentRequest.php
Normal file
7
app/Http/Requests/PaymentRequest.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php namespace App\Http\Requests;
|
||||||
|
|
||||||
|
class PaymentRequest extends EntityRequest {
|
||||||
|
|
||||||
|
protected $entityType = ENTITY_PAYMENT;
|
||||||
|
|
||||||
|
}
|
7
app/Http/Requests/TaskRequest.php
Normal file
7
app/Http/Requests/TaskRequest.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php namespace App\Http\Requests;
|
||||||
|
|
||||||
|
class TaskRequest extends EntityRequest {
|
||||||
|
|
||||||
|
protected $entityType = ENTITY_TASK;
|
||||||
|
|
||||||
|
}
|
26
app/Http/Requests/UpdateTaskRequest.php
Normal file
26
app/Http/Requests/UpdateTaskRequest.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php namespace App\Http\Requests;
|
||||||
|
|
||||||
|
class UpdateTaskRequest extends TaskRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->can('edit', $this->entity());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'time_log' => 'time_log',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
19
app/Http/Requests/VendorRequest.php
Normal file
19
app/Http/Requests/VendorRequest.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php namespace App\Http\Requests;
|
||||||
|
|
||||||
|
class VendorRequest extends EntityRequest {
|
||||||
|
|
||||||
|
protected $entityType = ENTITY_VENDOR;
|
||||||
|
|
||||||
|
public function entity()
|
||||||
|
{
|
||||||
|
$vendor = parent::entity();
|
||||||
|
|
||||||
|
// eager load the contacts
|
||||||
|
if ($vendor && ! count($vendor->vendorcontacts)) {
|
||||||
|
$vendor->load('vendorcontacts');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $vendor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -64,20 +64,6 @@ class TaskRepository
|
|||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getErrors($input)
|
|
||||||
{
|
|
||||||
$rules = [
|
|
||||||
'time_log' => 'time_log',
|
|
||||||
];
|
|
||||||
$validator = \Validator::make($input, $rules);
|
|
||||||
|
|
||||||
if ($validator->fails()) {
|
|
||||||
return $validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function save($publicId, $data)
|
public function save($publicId, $data)
|
||||||
{
|
{
|
||||||
if ($publicId) {
|
if ($publicId) {
|
||||||
|
@ -114,6 +114,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if ($errors->first('time_log'))
|
||||||
|
<div class="alert alert-danger"><li>{{ trans('texts.task_errors') }} </li></div>
|
||||||
|
@endif
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -455,7 +459,7 @@
|
|||||||
@endif
|
@endif
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if (Session::has('error'))
|
@if ($errors->first('time_log'))
|
||||||
loadTimeLog({!! json_encode(Input::old('time_log')) !!});
|
loadTimeLog({!! json_encode(Input::old('time_log')) !!});
|
||||||
model.showTimeOverlaps();
|
model.showTimeOverlaps();
|
||||||
showTimeDetails();
|
showTimeDetails();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user