56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Policies\Backend;
|
|
|
|
use App\Dto\OrderDto;
|
|
use App\Models\Customer;
|
|
use App\Models\Order;
|
|
use App\Models\User;
|
|
use Domain\Enums\OrderStatus;
|
|
use Domain\Enums\UserRole;
|
|
|
|
class OrderPolicy
|
|
{
|
|
public function viewAnyToday(User | Customer $user): bool
|
|
{
|
|
if ($user instanceof Customer) {
|
|
return false;
|
|
}
|
|
|
|
return $user->role->isAtLeastEqualsTo(UserRole::Admin);
|
|
}
|
|
|
|
public function viewAny(User | Customer $user): bool
|
|
{
|
|
if ($user instanceof Customer) {
|
|
return false;
|
|
}
|
|
|
|
return $user->role->isAtLeastEqualsTo(UserRole::Admin);
|
|
}
|
|
|
|
public function view(User | Customer $user, Order | OrderDto $_): bool
|
|
{
|
|
if ($user instanceof Customer) {
|
|
return false;
|
|
}
|
|
|
|
return $user->role->isAtLeastEqualsTo(UserRole::Admin);
|
|
}
|
|
|
|
/**
|
|
* Back-office admins may cancel any non-canceled order regardless of pickup_day
|
|
* as an administrative override (see REGLES METIERS.md section 5).
|
|
*/
|
|
public function cancel(User | Customer $user, Order | OrderDto $order): bool
|
|
{
|
|
if ($user instanceof Customer) {
|
|
return false;
|
|
}
|
|
|
|
return $user->role->isAtLeastEqualsTo(UserRole::Admin)
|
|
&& ! \in_array($order->status, [OrderStatus::CANCELED, OrderStatus::PENDING, OrderStatus::FAILED], true);
|
|
}
|
|
}
|