1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Policies/DocumentPolicy.php
2019-01-30 22:25:07 +11:00

53 lines
1.1 KiB
PHP

<?php
namespace App\Policies;
use App\Models\User;
use Illuminate\Support\Facades\Log;
/**
* Class DocumentPolicy.
*/
class DocumentPolicy extends EntityPolicy
{
/**
* @param User $user
* @param mixed $item
*
* @return bool
*/
public function create(User $user)
{
return ! empty($user);
}
/**
* @param User $user
* @param Document $document
*
* @return bool
*/
public function view(User $user, $document, $entityType = null)
{
if ($user->hasPermission(['view_expense', 'view_invoice'], true)) {
return true;
}
if ($document->expense) {
if ($document->expense->invoice) {
return $user->can('view', $document->expense->invoice);
}
return $user->can('view', $document->expense);
}
if ($document->invoice) {
return $user->can('view', $document->invoice);
}
if($document->ticket){
return $user->can('view', $document->ticket);
}
return $user->owns($document);
}
}