- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees) - Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue) - Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts - Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs - Remove legacy and dead CSV employee import/export code - Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation - Add comprehensive Pest unit, integration, and feature test coverage
121 lines
4.1 KiB
PHP
121 lines
4.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Dto\DiscountDto;
|
|
use App\Dto\FaqDto;
|
|
use App\Dto\PageDto;
|
|
use App\Dto\PickupExceptionDto;
|
|
use App\Dto\ProductDto;
|
|
use App\Dto\RangeDto;
|
|
use App\Dto\SettingDto;
|
|
use App\Dto\ShopDto;
|
|
use App\Dto\SlideDto;
|
|
use App\Dto\TagDto;
|
|
use App\Jobs\FetchAndUpsertArcadiaEmployees;
|
|
use App\Models\Customer;
|
|
use App\Models\Setting;
|
|
use App\Policies\Backend\DiscountPolicy;
|
|
use App\Policies\Backend\EmployeePolicy;
|
|
use App\Policies\Backend\FaqPolicy;
|
|
use App\Policies\Backend\PagePolicy;
|
|
use App\Policies\Backend\PickupExceptionPolicy;
|
|
use App\Policies\Backend\ProductPolicy;
|
|
use App\Policies\Backend\RangePolicy;
|
|
use App\Policies\Backend\SettingPolicy;
|
|
use App\Policies\Backend\ShopPolicy;
|
|
use App\Policies\Backend\SlidePolicy;
|
|
use App\Policies\Backend\TagPolicy;
|
|
use App\Policies\Frontend\BasketPolicy;
|
|
use App\Services\CrmService;
|
|
use Domain\Models\ValueObjects\BasketProduct;
|
|
use Domain\Services\ShopperService;
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
|
use Infrastructure\Adapters\Services\AppCustomerAuthService;
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* The policy mappings for the application.
|
|
*
|
|
* @var array<class-string, class-string>
|
|
*/
|
|
#[\Override]
|
|
protected $policies = [
|
|
// * Policies Exceptions
|
|
BasketProduct::class => BasketPolicy::class,
|
|
DiscountDto::class => DiscountPolicy::class,
|
|
FaqDto::class => FaqPolicy::class,
|
|
PageDto::class => PagePolicy::class,
|
|
PickupExceptionDto::class => PickupExceptionPolicy::class,
|
|
ProductDto::class => ProductPolicy::class,
|
|
RangeDto::class => RangePolicy::class,
|
|
Setting::class => SettingPolicy::class,
|
|
SettingDto::class => SettingPolicy::class,
|
|
ShopDto::class => ShopPolicy::class,
|
|
SlideDto::class => SlidePolicy::class,
|
|
TagDto::class => TagPolicy::class,
|
|
FetchAndUpsertArcadiaEmployees::class => EmployeePolicy::class,
|
|
];
|
|
|
|
/**
|
|
* Register any authentication / authorization services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
$this->app->singleton(
|
|
AppAdminAuthService::class,
|
|
fn ($app): AppAdminAuthService => new AppAdminAuthService(
|
|
Auth::guard('backend')
|
|
)
|
|
);
|
|
|
|
$this->app->singleton(
|
|
AppCustomerAuthService::class,
|
|
fn ($app): AppCustomerAuthService => new AppCustomerAuthService(
|
|
Auth::guard('frontend'),
|
|
$app->make(CrmService::class)
|
|
)
|
|
);
|
|
|
|
Auth::shouldUse($this->currentRouteGuard());
|
|
|
|
Gate::define(
|
|
'customerPassOrders',
|
|
fn (Customer $customer): bool => resolve(ShopperService::class)
|
|
->canCustomerPassOrdersApp($customer->getId())
|
|
);
|
|
|
|
$this->registerPolicies();
|
|
|
|
Gate::guessPolicyNamesUsing(function (string $modelClass) {
|
|
$context = $this->currentRouteGuard() === 'frontend' ? 'Frontend' : 'Backend';
|
|
$classBasename = str_replace('Dto', '', class_basename($modelClass));
|
|
|
|
$policyClass = "App\\Policies\\{$context}\\{$classBasename}Policy";
|
|
|
|
return class_exists($policyClass) ? $policyClass : null;
|
|
});
|
|
}
|
|
|
|
private function currentRouteGuard(): string
|
|
{
|
|
$request = $this->app->make(Request::class);
|
|
$defaultGuard = Config::string('auth.defaults.guard', 'frontend');
|
|
|
|
return match (true) {
|
|
$request->is('bo', 'bo/*') => 'backend',
|
|
$request->is('api', 'api/*') => 'api',
|
|
default => $defaultGuard,
|
|
};
|
|
}
|
|
}
|