98 lines
4.8 KiB
PHP
98 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\ExistingBusiness;
|
|
use App\Services\ContentManagement;
|
|
use App\Services\InvestorPath;
|
|
use App\Services\LegacyContent;
|
|
use App\Services\OpportunityManagement;
|
|
use App\Services\PortalProfileAccess;
|
|
use App\Services\Procurement;
|
|
use App\Services\ScopedPortalAdministration;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Middleware;
|
|
|
|
class HandleInertiaRequests extends Middleware
|
|
{
|
|
/**
|
|
* The root template that's loaded on the first page visit.
|
|
*
|
|
* @see https://inertiajs.com/server-side-setup#root-template
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $rootView = 'app';
|
|
|
|
/**
|
|
* Determines the current asset version.
|
|
*
|
|
* @see https://inertiajs.com/asset-versioning
|
|
*/
|
|
public function version(Request $request): ?string
|
|
{
|
|
if (app()->environment('testing') && config('portal.qa_build_directory')) {
|
|
$manifest = public_path(config('portal.qa_build_directory').'/manifest.json');
|
|
|
|
$version = is_file($manifest) ? hash_file('xxh128', $manifest) : false;
|
|
|
|
return $version === false ? null : $version;
|
|
}
|
|
|
|
return parent::version($request);
|
|
}
|
|
|
|
/**
|
|
* Define the props that are shared by default.
|
|
*
|
|
* @see https://inertiajs.com/shared-data
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function share(Request $request): array
|
|
{
|
|
$contentManagementAccess = app(ContentManagement::class)->access($request->user());
|
|
|
|
return [
|
|
...parent::share($request),
|
|
'name' => config('app.name'),
|
|
'procurementEnabled' => app(Procurement::class)->available(),
|
|
'homologationReserved' => (bool) config('portal.homologation_only', false),
|
|
'profileAccess' => app(PortalProfileAccess::class)->navigation($request->user()),
|
|
'contentManagementHref' => $contentManagementAccess !== [] ? '/gestao-conteudos' : null,
|
|
'contentManagementAccess' => $contentManagementAccess,
|
|
'portalOperator' => config('portal.operator_name'),
|
|
'portalInstitutionalContactEmail' => filter_var(config('portal.institutional_contact_email'), FILTER_VALIDATE_EMAIL) ?: null,
|
|
'legacyContentEnabled' => app(LegacyContent::class)->available(),
|
|
'educationEnabled' => (bool) config('education.enabled', false),
|
|
'aiEnabled' => (bool) config('investmoz_ai.enabled', false),
|
|
'existingBusinessEnabled' => (bool) config('existing-business.enabled', false),
|
|
'businessReviewUrl' => config('existing-business.enabled') && $request->user()?->can('reviewQueue', ExistingBusiness::class)
|
|
? '/management/negocios' : null,
|
|
'investorPathEnabled' => app(InvestorPath::class)->available(),
|
|
'opportunityManagement' => config('portal.opportunity_dashboard_access_enabled') && $request->user() && app(PortalProfileAccess::class)->legacyWriteAllowed($request->user()) ? [
|
|
'installed' => app(OpportunityManagement::class)->installed(),
|
|
'manage' => ['label' => 'Gestão de Oportunidades', 'href' => '/management/opportunities'],
|
|
'create' => ['label' => 'Nova oportunidade', 'href' => '/management/opportunities/create'],
|
|
'installationHref' => '/management/opportunity-management-install',
|
|
] : null,
|
|
'flash' => ['success' => fn () => $request->session()->get('success'), 'warning' => fn () => $request->session()->get('warning'), 'uploaded_document_id' => fn () => $request->session()->get('uploaded_document_id')],
|
|
'scopedAdministration' => $request->user() && app(ScopedPortalAdministration::class)->administrative($request->user()) ? [
|
|
['label' => 'Zonas e parques', 'href' => '/management/investment/zones'],
|
|
['label' => 'Referências económicas', 'href' => '/management/economic-references/lot-01'],
|
|
['label' => 'Referências e formulários', 'href' => '/management/investment/references'],
|
|
['label' => 'Educação e competências', 'href' => '/management/education'],
|
|
['label' => 'Interesses atribuídos', 'href' => '/management/interests'],
|
|
['label' => 'Atribuições de interesses', 'href' => '/management/interests/atribuicoes'],
|
|
['label' => 'Atribuições do Balcão', 'href' => '/management/balcao/atribuicoes'],
|
|
] : [],
|
|
'auth' => [
|
|
'user' => $request->user(),
|
|
'canManagePortal' => $request->user()?->can('manage-portal') ?? false,
|
|
'legacyManagementAccess' => $request->user()?->hasVerifiedEmail() && app(PortalProfileAccess::class)->legacyWriteAllowed($request->user()),
|
|
],
|
|
'sidebarOpen' => ! $request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
|
|
];
|
|
}
|
|
}
|