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