mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01:00
61 lines
1.2 KiB
PHP
61 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
/**
|
|
* Class EntityPolicy
|
|
*/
|
|
class EntityPolicy
|
|
{
|
|
use HandlesAuthorization;
|
|
|
|
/**
|
|
* @param User $user
|
|
* @return bool
|
|
*/
|
|
public static function create(User $user) {
|
|
return $user->hasPermission('create_all');
|
|
}
|
|
|
|
/**
|
|
* @param User $user
|
|
* @param $item
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function edit(User $user, $item) {
|
|
return $user->hasPermission('edit_all') || $user->owns($item);
|
|
}
|
|
|
|
/**
|
|
* @param User $user
|
|
* @param $item
|
|
*
|
|
* @return bool
|
|
*/
|
|
public static function view(User $user, $item) {
|
|
return $user->hasPermission('view_all') || $user->owns($item);
|
|
}
|
|
|
|
/**
|
|
* @param User $user
|
|
* @param $ownerUserId
|
|
* @return bool
|
|
*/
|
|
public static function viewByOwner(User $user, $ownerUserId) {
|
|
return $user->hasPermission('view_all') || $user->id == $ownerUserId;
|
|
}
|
|
|
|
/**
|
|
* @param User $user
|
|
* @param $ownerUserId
|
|
* @return bool
|
|
*/
|
|
public static function editByOwner(User $user, $ownerUserId) {
|
|
return $user->hasPermission('edit_all') || $user->id == $ownerUserId;
|
|
}
|
|
}
|