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

75 lines
1.7 KiB
PHP

<?php
namespace App\Services;
use App\Ninja\Datatables\CreditDatatable;
use App\Ninja\Repositories\CreditRepository;
use Auth;
use Utils;
/**
* Class CreditService.
*/
class CreditService extends BaseService
{
/**
* @var CreditRepository
*/
protected $creditRepo;
/**
* @var DatatableService
*/
protected $datatableService;
/**
* CreditService constructor.
*
* @param CreditRepository $creditRepo
* @param DatatableService $datatableService
*/
public function __construct(CreditRepository $creditRepo, DatatableService $datatableService)
{
$this->creditRepo = $creditRepo;
$this->datatableService = $datatableService;
}
/**
* @return CreditRepository
*/
protected function getRepo()
{
return $this->creditRepo;
}
/**
* @param $data
* @param null|mixed $credit
*
* @return mixed|null
*/
public function save($data, $credit = null)
{
return $this->creditRepo->save($data, $credit);
}
/**
* @param $clientPublicId
* @param $search
*
* @return \Illuminate\Http\JsonResponse
*/
public function getDatatable($clientPublicId, $search)
{
// we don't support bulk edit and hide the client on the individual client page
$datatable = new CreditDatatable(true, $clientPublicId);
$query = $this->creditRepo->find($clientPublicId, $search);
if (! Utils::hasPermission('view_credit')) {
$query->where('credits.user_id', '=', Auth::user()->id);
}
return $this->datatableService->createDatatable($datatable, $query);
}
}