64 lines
2.0 KiB
PHP
64 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\User;
|
|
use App\Models\InventoryTransaction;
|
|
|
|
class InventoryTransactionPolicy
|
|
{
|
|
/**
|
|
* Determine whether the user can view any inventory transactions.
|
|
*/
|
|
public function viewAny(User $user): bool
|
|
{
|
|
return $user->tenant_id === session('tenant_id')
|
|
&& ($user->hasRole('admin')
|
|
|| $user->hasRole('manager')
|
|
|| $user->hasPermissionTo('manage inventory'));
|
|
}
|
|
|
|
/**
|
|
* 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->hasRole('admin')
|
|
|| $user->hasRole('manager')
|
|
|| $user->hasPermissionTo('manage inventory'));
|
|
}
|
|
|
|
/**
|
|
* Determine whether the user can create inventory transactions.
|
|
*/
|
|
public function create(User $user): bool
|
|
{
|
|
return $user->tenant_id === session('tenant_id')
|
|
&& ($user->hasRole('admin')
|
|
|| $user->hasRole('manager')
|
|
|| $user->hasPermissionTo('manage inventory'));
|
|
}
|
|
|
|
/**
|
|
* 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->hasRole('admin')
|
|
|| $user->hasRole('manager')
|
|
|| $user->hasPermissionTo('manage inventory'));
|
|
}
|
|
|
|
/**
|
|
* 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->hasRole('admin')
|
|
|| $user->hasPermissionTo('manage inventory'));
|
|
}
|
|
}
|