path(), $match)) { $id = (int) $match[1]; } elseif ($request->is('management/opportunity-origin/preview', 'management/opportunity-origin/apply')) { $id = filter_var($request->input('id'), FILTER_VALIDATE_INT) ?: null; } elseif ($request->is('api/v2/investment/admin/zones/*/links')) { $id = filter_var($request->input('opportunity_id'), FILTER_VALIDATE_INT) ?: null; } if ($request->user() && $id !== null && Schema::hasColumn('opportunities', 'owner_user_id')) { $record = Opportunity::withTrashed()->find($id); if ($record && $record->owner_user_id === null && ! $request->isMethod('GET')) { abort_unless(app(PortalProfileAccess::class)->legacyWriteAllowed($request->user()), 403, 'O papel v1 não contorna os controlos através de um registo legado.'); } if ($record && ($record->owner_user_id !== null || str_starts_with($request->path(), 'minhas-oportunidades'))) { abort_if($record->owner_user_id === null && str_starts_with($request->path(), 'minhas-oportunidades'), 403, 'Registo legado não convertido para a política v1.'); $access = app(PortalProfileAccess::class); $access->authorize($request->user(), $request->isMethod('GET') || str_ends_with($request->path(), '/workflow') || str_ends_with($request->path(), '/preview') || $request->is('minhas-oportunidades/*/classification/review') ? 'view' : 'edit', $record); abort_if($request->is('management/opportunity-origin/apply'), 403, 'O cadastro privado v1 não usa a classificação editorial dos exemplos legados.'); abort_if($request->isMethod('POST') && str_ends_with($request->path(), '/lifecycle') && ! str_contains($request->path(), '/resources/'), 403, 'Use o workflow com decisões segregadas; o perfil não concede exclusão.'); } } return $next($request); } }