1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00
invoiceninja/app/Services/TaskService.php
David Bomba a9f2d0d855
This PR implements Create/View/Edit permissions based on ENTITY TYPE (ie invoice/expense/client). (#2150)
* migration for new permissions schema

* update permissions across data tables

* refactor migrations to prevent duplicate attribute

* update permissions in views

* Product Permissions

* permissions via controllers

* Refactor to use Laravel authorization gate

* Doc Blocks for EntityPolicy

* check permissions conditional on create new client

* Bug Fixes

* Data table permissions

* working on UI

* settings UI/UX finalised

* Datatable permissions

* remove legacy permissions

* permission fix for viewing client

* remove all instances of viewByOwner

* refactor after PR

* Bug fix for Functional test and implementation of Functional tests for Permissions

* fix for tests
2018-06-07 20:08:34 +10:00

62 lines
1.4 KiB
PHP

<?php
namespace App\Services;
use App\Ninja\Datatables\ProjectTaskDatatable;
use App\Ninja\Datatables\TaskDatatable;
use App\Ninja\Repositories\TaskRepository;
use Auth;
use Utils;
/**
* Class TaskService.
*/
class TaskService extends BaseService
{
protected $datatableService;
protected $taskRepo;
/**
* TaskService constructor.
*
* @param TaskRepository $taskRepo
* @param DatatableService $datatableService
*/
public function __construct(TaskRepository $taskRepo, DatatableService $datatableService)
{
$this->taskRepo = $taskRepo;
$this->datatableService = $datatableService;
}
/**
* @return TaskRepository
*/
protected function getRepo()
{
return $this->taskRepo;
}
/**
* @param $clientPublicId
* @param $search
*
* @return \Illuminate\Http\JsonResponse
*/
public function getDatatable($clientPublicId, $projectPublicId, $search)
{
if ($projectPublicId) {
$datatable = new ProjectTaskDatatable(true, true);
} else {
$datatable = new TaskDatatable(true, $clientPublicId);
}
$query = $this->taskRepo->find($clientPublicId, $projectPublicId, $search);
if (! Utils::hasPermission('view_task')) {
$query->where('tasks.user_id', '=', Auth::user()->id);
}
return $this->datatableService->createDatatable($datatable, $query);
}
}