56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\User;
|
|
use App\Models\InventoryTransaction;
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
class InventoryTransactionPolicy
|
|
{
|
|
use HandlesAuthorization;
|
|
|
|
/**
|
|
* Determine whether the user can view any inventory transactions.
|
|
*/
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return $user->can('inventory.view') || $user->can('inventory.update');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can view the inventory transaction.
|
|
*/
|
|
public function view(User $user, InventoryTransaction $inventoryTransaction): bool
|
|
{
|
|
return $user->tenant_id === $inventoryTransaction->tenant_id
|
|
&& ($user->can('inventory.view') || $user->can('inventory.update'));
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create inventory transactions.
|
|
*/
|
|
public function create(User $user): bool
|
|
{
|
|
return $user->can('inventory.create');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can update the inventory transaction.
|
|
*/
|
|
public function update(User $user, InventoryTransaction $inventoryTransaction): bool
|
|
{
|
|
return $user->tenant_id === $inventoryTransaction->tenant_id
|
|
&& $user->can('inventory.update');
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can delete the inventory transaction.
|
|
*/
|
|
public function delete(User $user, InventoryTransaction $inventoryTransaction): bool
|
|
{
|
|
return $user->tenant_id === $inventoryTransaction->tenant_id
|
|
&& $user->can('inventory.delete');
|
|
}
|
|
}
|