@@ -9,6 +9,7 @@ use App\Services\OpportunityImageProcessor;
|
||||
use App\Services\OpportunityManagement;
|
||||
use App\Services\OpportunityResourceInstallation;
|
||||
use App\Services\OpportunityResources;
|
||||
use App\Services\OrganizationCountryInstallation;
|
||||
use App\Services\PortalProfileAccess;
|
||||
use App\Services\VerifiedDocumentBinary;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -16,6 +17,7 @@ use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Str;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
@@ -38,6 +40,39 @@ class OpportunityResourceController extends Controller
|
||||
return back()->with('success', 'Recursos instalados; nenhum ficheiro publicado ou oportunidade submetida.');
|
||||
}
|
||||
|
||||
public function organizationCountryPreview(Request $request, OrganizationCountryInstallation $service): JsonResponse|Response
|
||||
{
|
||||
$plan = $service->preview($request->user());
|
||||
$scope = $this->countryOperationScope($request, $plan);
|
||||
$operation = $request->session()->get('portal.country_installation_operation');
|
||||
if (! is_array($operation) || ($operation['scope'] ?? null) !== $scope) {
|
||||
$operation = ['scope' => $scope, 'key' => (string) Str::uuid()];
|
||||
$request->session()->put('portal.country_installation_operation', $operation);
|
||||
}
|
||||
$plan = [...$plan, 'operationKey' => $operation['key'], 'actionUrl' => '/management/opportunity-resources-install/organization-country', 'extension' => true];
|
||||
|
||||
return $request->expectsJson() ? response()->json($plan) : Inertia::render('management/opportunity-install', $plan);
|
||||
}
|
||||
|
||||
public function organizationCountryApply(Request $request, OrganizationCountryInstallation $service): JsonResponse|RedirectResponse
|
||||
{
|
||||
// Preview authorizes the actor; the UUID remains stable until this scope changes or logout.
|
||||
$plan = $service->preview($request->user());
|
||||
$operation = $request->session()->get('portal.country_installation_operation');
|
||||
$data = $request->validate(['idempotency_key' => 'required|uuid']);
|
||||
abort_unless(is_array($operation) && ($operation['scope'] ?? null) === $this->countryOperationScope($request, $plan)
|
||||
&& hash_equals($operation['key'], $data['idempotency_key']), 409, 'A operação não corresponde a esta prévia. Atualize a página antes de tentar novamente.');
|
||||
$result = $service->apply($request->user(), $request->all());
|
||||
|
||||
return $request->expectsJson() ? response()->json($result) : back()->with('success', 'País mestre instalado; nenhuma submissão anterior alterada.');
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $plan */
|
||||
private function countryOperationScope(Request $request, array $plan): string
|
||||
{
|
||||
return hash('sha256', json_encode([$request->user()->getAuthIdentifier(), $plan['target'], $plan['migration'], $plan['code_hash']], JSON_THROW_ON_ERROR));
|
||||
}
|
||||
|
||||
public function index(int $id, OpportunityResources $service): Response
|
||||
{
|
||||
$opportunity = Opportunity::withTrashed()->findOrFail($id);
|
||||
|
||||
Reference in New Issue
Block a user