ldc-cocotte/app/Policies/Backend/OrderPolicy.php

57 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace App\Policies\Backend;
use App\Dto\OrderDto;
2026-06-14 21:32:07 +02:00
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
2026-06-14 21:32:07 +02:00
{
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
2026-06-14 21:32:07 +02:00
{
if ($user instanceof Customer) {
return false;
}
return $user->role->isAtLeastEqualsTo(UserRole::Admin)
&& ! \in_array($order->status, [OrderStatus::CANCELED, OrderStatus::PENDING, OrderStatus::FAILED], true);
2026-06-14 21:32:07 +02:00
}
}