1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
invoiceninja/app/Policies/DocumentPolicy.php

47 lines
924 B
PHP
Raw Normal View History

2016-04-26 03:53:39 +02:00
<?php
namespace App\Policies;
use App\Models\Document;
use App\Models\User;
/**
* Class DocumentPolicy
*/
class DocumentPolicy extends EntityPolicy
{
/**
* @param User $user
*
* @return bool
*/
public static function create(User $user)
{
2016-04-26 03:53:39 +02:00
return !empty($user);
}
/**
* @param User $user
* @param $item
*
* @return bool
*/
public static function view(User $user, $item)
{
if ($user->hasPermission('view_all')) {
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);
}
return $user->owns($item);
2016-04-26 03:53:39 +02:00
}
2016-07-14 11:01:05 +02:00
}