1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/app/Services/VendorService.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

80 lines
1.7 KiB
PHP

<?php
namespace App\Services;
use App\Models\Vendor;
use App\Ninja\Datatables\VendorDatatable;
use App\Ninja\Repositories\NinjaRepository;
use App\Ninja\Repositories\VendorRepository;
use Auth;
use Utils;
/**
* Class VendorService.
*/
class VendorService extends BaseService
{
/**
* @var VendorRepository
*/
protected $vendorRepo;
/**
* @var DatatableService
*/
protected $datatableService;
/**
* VendorService constructor.
*
* @param VendorRepository $vendorRepo
* @param DatatableService $datatableService
* @param NinjaRepository $ninjaRepo
*/
public function __construct(
VendorRepository $vendorRepo,
DatatableService $datatableService,
NinjaRepository $ninjaRepo
) {
$this->vendorRepo = $vendorRepo;
$this->ninjaRepo = $ninjaRepo;
$this->datatableService = $datatableService;
}
/**
* @return VendorRepository
*/
protected function getRepo()
{
return $this->vendorRepo;
}
/**
* @param array $data
* @param Vendor|null $vendor
*
* @return mixed|null
*/
public function save(array $data, Vendor $vendor = null)
{
return $this->vendorRepo->save($data, $vendor);
}
/**
* @param $search
*
* @return \Illuminate\Http\JsonResponse
*/
public function getDatatable($search)
{
$datatable = new VendorDatatable();
$query = $this->vendorRepo->find($search);
if (! Utils::hasPermission('view_vendor')) {
$query->where('vendors.user_id', '=', Auth::user()->id);
}
return $this->datatableService->createDatatable($datatable, $query);
}
}