Em produção, os pedidos de interesse feitos em /apoio nunca foram vistos: só o caminho da API enfileirava o aviso à equipa. O aviso passa para o InterestSubmission::receive, por onde passam todos os caminhos de entrada, e a submissão de um pedido no Balcão Virtual passa a avisar também a equipa (até aqui só o proponente e um analista já atribuído recebiam aviso interno). - TeamNotifications: fila transaccional comum (só existe aviso se o registo ficou gravado); destinatários de PORTAL_NOTIFICATION_RECIPIENTS, sem dados pessoais nas mensagens. - NotifyDeskRequestSubmitted: protocolo e ligações protegidas de triagem. - DemographicInstallation aceita também o domínio público como a mesma instalação de produção, para o APP_URL poder passar a investemoz.tempo.co.mz. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jm
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Http\Controllers\Api\V1;
|
||||
use App\Domain\Interests\Enums\InterestStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StoreInterestRequestRequest;
|
||||
use App\Jobs\NotifyInterestReceived;
|
||||
use App\Models\ExistingBusiness;
|
||||
use App\Models\InterestRequest;
|
||||
use App\Models\InvestmentSubmission;
|
||||
@@ -16,7 +15,6 @@ use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
@@ -68,18 +66,6 @@ class InterestRequestController extends Controller
|
||||
'ip_address' => $request->ip(),
|
||||
'user_agent' => $request->userAgent(),
|
||||
]);
|
||||
if (config('portal.notifications_enabled')) {
|
||||
$connection = config('queue.connections.database.connection');
|
||||
if (config('queue.connections.database.after_commit') || ($connection && $connection !== config('database.default'))) {
|
||||
throw new \RuntimeException('Portal notifications require the transactional database queue.');
|
||||
}
|
||||
foreach (array_unique(config('portal.notification_recipients')) as $recipient) {
|
||||
if (filter_var($recipient, FILTER_VALIDATE_EMAIL)) {
|
||||
Queue::connection('database')->push(new NotifyInterestReceived($interest->id, $recipient));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$row = InvestmentSubmission::create([
|
||||
'user_id' => $request->user()->id, 'opportunity_id' => $opportunity?->id,
|
||||
'interest_request_id' => $interest->id, 'status' => 'submitted', 'version' => 1,
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
/** Internal notice that a Virtual Desk request was submitted: protocol and protected links only. */
|
||||
class NotifyDeskRequestSubmitted implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public int $tries = 3;
|
||||
|
||||
public int $timeout = 30;
|
||||
|
||||
public function __construct(public string $requestId, public string $recipient) {}
|
||||
|
||||
/** @return list<int> */
|
||||
public function backoff(): array
|
||||
{
|
||||
return [60, 300, 900];
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
if (! config('portal.notifications_enabled') || ! in_array($this->recipient, config('portal.notification_recipients'), true)) {
|
||||
return;
|
||||
}
|
||||
$request = DB::table('desk_requests')->where('id', $this->requestId)->first(['id', 'protocol', 'status', 'analyst_id']);
|
||||
if (! $request || $request->status !== 'submitted') {
|
||||
return; // Already picked up, returned or withdrawn before the notice left.
|
||||
}
|
||||
$assignment = $request->analyst_id ? 'Já tem responsável atribuído.' : 'Ainda sem responsável: atribua-o na triagem.';
|
||||
$body = "Foi submetido um pedido no Balcão Virtual: {$request->protocol}.\n{$assignment}\n\n"
|
||||
."Triagem e atribuição:\n".url('/management/balcao/atribuicoes')."\n\nPedido:\n".url('/balcao-virtual/pedidos/'.$request->id);
|
||||
Mail::raw($body, fn ($message) => $message->to($this->recipient)->subject('Novo pedido no Balcão Virtual — '.$request->protocol));
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,8 @@ final class DemographicInstallation
|
||||
public function activeTarget(): bool
|
||||
{
|
||||
$c = config('database.connections.pgsql');
|
||||
$homologation = config('app.url') === 'https://teste-investidor.tempo.co.mz'
|
||||
// The production install answers on both names (public domain and the original homologation one).
|
||||
$homologation = in_array(config('app.url'), ['https://teste-investidor.tempo.co.mz', 'https://investemoz.tempo.co.mz'], true)
|
||||
&& config('demography.enabled', false) && $c['database'] === 'teste_investidor';
|
||||
if (app()->environment('testing') || config('database.default') !== 'pgsql' || ! empty($c['url'])
|
||||
|| ! in_array($c['host'], ['127.0.0.1', 'localhost'], true) || (int) $c['port'] !== 5432
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Jobs\NotifyInterestReceived;
|
||||
use App\Models\InterestRequest;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -62,6 +63,9 @@ final class InterestSubmission
|
||||
'interest_request_id' => $interest->id, 'created_at' => now(),
|
||||
]);
|
||||
}
|
||||
// Every intake path (public support form, investor workspace, investment and land
|
||||
// submissions, API) passes here, so the team is told about each new interest once.
|
||||
TeamNotifications::queue(fn (string $recipient) => new NotifyInterestReceived($interest->id, $recipient));
|
||||
|
||||
return $interest;
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
|
||||
/**
|
||||
* Internal e-mail notices to the Tempo team (PORTAL_NOTIFICATION_RECIPIENTS).
|
||||
* Queued inside the caller's transaction on the database queue, so a notice exists
|
||||
* only if the business record was stored. Jobs carry identifiers, never personal data.
|
||||
*/
|
||||
final class TeamNotifications
|
||||
{
|
||||
/** @param Closure(string): ShouldQueue $jobFor */
|
||||
public static function queue(Closure $jobFor): void
|
||||
{
|
||||
if (! config('portal.notifications_enabled')) {
|
||||
return;
|
||||
}
|
||||
$connection = config('queue.connections.database.connection');
|
||||
if (config('queue.connections.database.after_commit') || ($connection && $connection !== config('database.default'))) {
|
||||
throw new \RuntimeException('Portal notifications require the transactional database queue.');
|
||||
}
|
||||
foreach (array_unique(config('portal.notification_recipients')) as $recipient) {
|
||||
if (filter_var($recipient, FILTER_VALIDATE_EMAIL)) {
|
||||
Queue::connection('database')->push($jobFor($recipient));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Jobs\NotifyDeskRequestSubmitted;
|
||||
use App\Models\InvestmentSubmission;
|
||||
use App\Models\Investor;
|
||||
use App\Models\InvestorJourney;
|
||||
@@ -556,9 +557,14 @@ class VirtualDesk
|
||||
if ($submit) {
|
||||
$updates = [...$updates, 'status' => 'submitted', 'protocol' => $request->protocol ?? 'BV-'.date('Y').'-'.strtoupper(str_replace('-', '', $id)), 'submitted_at' => now(), 'submitted_snapshot' => $this->encode($snapshot)];
|
||||
}
|
||||
$previousStatus = $request->status;
|
||||
DB::table('desk_requests')->where('id', $id)->update($updates);
|
||||
$request = DB::table('desk_requests')->where('id', $id)->firstOrFail();
|
||||
$this->event($case, $actor, $submit ? 'submitted' : 'draft_saved', ['reason' => $data['reason'] ?? '', 'findings' => $findings], $request);
|
||||
if ($submit && $previousStatus !== 'submitted') {
|
||||
// The in-app notice reaches only the owner and an analyst already assigned; tell the team.
|
||||
TeamNotifications::queue(fn (string $recipient) => new NotifyDeskRequestSubmitted($id, $recipient));
|
||||
}
|
||||
if (($data['context_reviewed'] ?? false) && ! $submit) {
|
||||
$this->event($case, $actor, 'request_context_reviewed', ['investment_context_revision' => app(InvestorContext::class)->state($case)['revision']], $request);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user