Skip to content

add evento de auditoria no envio de e-mails de recurso publicado - #58

Merged
CaffeineIssues merged 2 commits into
developfrom
feature/published-recourse-email-audit
Dec 4, 2026
Merged

CaffeineIssues merged 2 commits into
developfrom
feature/published-recourse-email-audit

Conversation

@CaffeineIssues

@CaffeineIssues CaffeineIssues commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

✅ Descrição do propósito desse Pull Request

Registra a auditoria dos e-mails de resposta de recurso enviados pelo ConsumePublishedRecourseEmails, permitindo rastrear o recurso, o destinatário e a data do envio.

obs: necessario mergear o PR do plugin de recurso

🧭 Referência a Issue

[#49 ]

❓ O que foi feito para atingir isso?

  • Criado o EmailSentEvent, disparado após o envio bem-sucedido e a confirmação da mensagem no RabbitMQ.
  • Criado o listener RecordEmailDispatch, que utiliza o modelo existente EmailDispatch para persistir o envio e gerar a auditoria.
  • Registrados destinatário, assunto, conteúdo, tipo de e-mail, timestamp e metadados, incluindo recourse_id.
  • Tratadas falhas de auditoria com registro em log e Sentry, sem interromper o consumidor ou provocar reenvio do e-mail.
  • Adicionados testes do evento e da persistência da auditoria.

🏃‍♀️ Tipo de mudança

Marque as opções relevantes:

  • Bug fix (correção de bug)
  • Nova feature (mudança não retrocompatível que adiciona funcionalidade)
  • Mudança de breaking (correção ou feature que faria com que a funcionalidade existente não funcionasse como esperado)
  • Documentação (somente mudanças ou atualizações na documentação)

🕵️ Como foi testado?

  • Critério de aceitação
  • Testes de software (TDD, BDD, UNITÁRIO, INTEGRAÇÃO, E2E)

Checklist: ✔️

  • Meu código segue as diretrizes do projeto
  • Eu fiz um code review com minha equipe
  • Eu comentei meu código, especialmente em áreas de difícil entendimento
  • Eu atualizei a documentação correspondente
  • Testes novos e existentes passaram localmente com minhas alterações

Observação:

Summary by CodeRabbit

  • New Features
    • Successful published-recourse email sends are now recorded in dispatch history, including the recipient, subject, message content, send time, and available recourse details.
    • Email records include a sent status and associated audit history.
  • Bug Fixes
    • If recording an email dispatch encounters an error, the email-processing result is unaffected.

@CaffeineIssues CaffeineIssues self-assigned this Dec 4, 2026
@Junior-Shyko
Junior-Shyko self-requested a review December 4, 2026 14:17
@Junior-Shyko

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2c1ffa29-e4d8-4e80-afbf-65b7c7df83dc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Published-recourse email processing now dispatches an email-sent event after a successful send and acknowledgment. A registered listener records the email details and timestamps in an EmailDispatch record. Tests cover event contents, database recording, missing-email handling, and listener exceptions.

Changes: Email dispatch audit

Layer / File(s) Summary
Event contract and dispatch recording
app/Events/EmailSentEvent.php, app/Listeners/RecordEmailDispatch.php, app/Providers/EventServiceProvider.php, tests/Feature/RecordEmailDispatchTest.php
The event carries recipient, subject, mailable type, send time, optional metadata, and optional content. The registered listener creates a sent EmailDispatch record with the event values and timestamps. The feature test checks the record and its creation audit row.
Published-recourse email integration
app/Console/Commands/ConsumePublishedRecourseEmails.php, tests/Unit/Console/Commands/ConsumePublishedRecourseEmailsTest.php
After a successful send and acknowledgment, the command dispatches an event with rendered email content and recourse metadata. If event recording throws, the command captures the exception in Sentry and logs it. Tests cover event contents, missing email, and a throwing listener.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ConsumePublishedRecourseEmails
  participant EmailSentEvent
  participant RecordEmailDispatch
  participant EmailDispatch
  ConsumePublishedRecourseEmails->>EmailSentEvent: Dispatch email details after successful send and acknowledgment
  EmailSentEvent->>RecordEmailDispatch: Invoke registered listener
  RecordEmailDispatch->>EmailDispatch: Create sent dispatch record
Loading

Suggested reviewers: ronnyjohnti

Merge Risk: Minimal · previous review 448a5

This change records an audit entry for each published-recourse email after it is sent. Audit failures are logged and do not affect email delivery, so no actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: an audit event added to the sending of published-recourse emails. The changeset adds EmailSentEvent, the RecordEmailDispatch listener, and tests that record an audit e…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: an audit event added to the sending of published-recourse emails. The changeset adds EmailSentEvent, the RecordEmailDispatch listener, and tests that record an audit entry when ConsumePublishedRecourseEmails sends an email. The title is concise and specific, and it is written in Portuguese, which matches the PR objectives.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7dba8281-e5f9-409e-ba0b-dae78f455485
Commits

Reviewing files that changed from the base of the PR and between 5e27064 and 448a588.

Files selected for processing: 6

  • app/Console/Commands/ConsumePublishedRecourseEmails.php
  • app/Events/EmailSentEvent.php
  • app/Listeners/RecordEmailDispatch.php
  • app/Providers/EventServiceProvider.php
  • tests/Feature/RecordEmailDispatchTest.php
  • tests/Unit/Console/Commands/ConsumePublishedRecourseEmailsTest.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Event::assertNotDispatched(EmailSentEvent::class);
}

public function test_falha_na_auditoria_nao_interrompe_o_consumer(): void

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colocar os testes em ingles mantendo o padrao

// A mensagem de erro do command também acessa $data['email']
try {
$this->invokeProcessMessage($msgMock);
} catch (\ErrorException) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evitar de mascarar erros errais. Usar $this->expectException()

private function recordDispatch(array $data): void
{
try {
$mailable = new PublishedRecourse($data);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideal usar a propria instancia da classe no método sendEmail()

@jeff-doliveira1
jeff-doliveira1 self-requested a review December 4, 2026 18:44
@CaffeineIssues
CaffeineIssues merged commit eb6bbaf into develop Dec 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants