Skip to content

Notify moderators about submitted reports#438

Merged
Producdevity merged 3 commits into
stagingfrom
fix/moderator-report-notifications
Jun 6, 2026
Merged

Notify moderators about submitted reports#438
Producdevity merged 3 commits into
stagingfrom
fix/moderator-report-notifications

Conversation

@Producdevity

@Producdevity Producdevity commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Description

  • Send report-created notifications for handheld report submissions from web and mobile.
  • Send the same report-created notification for PC report submissions.
  • Target moderator-role users and above for new report notifications, including a moderator who submitted the report.
  • Share the report notification payload so handheld and PC reports use consistent labels and admin report links.
  • Sanitize PC/mobile report descriptions before storing them, matching the existing handheld web behavior.

Fixes #390

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor
  • Other (please describe):

How Has This Been Tested?

  • Local build
  • Lint
  • Typecheck
  • Unit tests
  • Manual testing

Commands run:

./node_modules/.bin/vitest run src/server/api/routers/listingReports.test.ts src/server/api/routers/mobile/listingReports.test.ts src/server/api/routers/pcListings.test.ts src/server/notifications/service.test.ts
./node_modules/.bin/next typegen
./node_modules/.bin/tsc --noEmit --pretty false
./node_modules/.bin/eslint .

ESLint completed with 0 errors; existing React Compiler warnings remain outside this change.

Screenshots (if applicable)

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • I have checked that all checks (lint, typecheck, test) pass

Notes for reviewers

No docs change needed.

Summary by CodeRabbit

  • New Features

    • Moderation notifications for report creation (new report events delivered to moderators).
  • Bug Fixes

    • More robust report submission and validation to prevent duplicates and invalid reports.
  • Improvements

    • Admin review links now go directly to the reported listing for faster review.
    • Mobile and web report flows unified for consistent behavior.

@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
emuready Ready Ready Preview, Comment Jun 6, 2026 3:37pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ccdeed91-59fc-4e9a-b4a8-7b68c338327e

📥 Commits

Reviewing files that changed from the base of the PR and between c596f64 and 7142dd1.

📒 Files selected for processing (2)
  • src/lib/errors.ts
  • src/server/services/report-submission.service.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/server/services/report-submission.service.ts

Walkthrough

Routers (web, mobile, PC) now delegate report creation to ReportSubmissionService which sanitizes input, enforces existence/self/duplicate checks, persists reports, and emits report.created notifications. Notification event types and recipient filtering/tests were added; admin UI links were adjusted.

Changes

Listing Report Creation Notifications

Layer / File(s) Summary
Notification event types and emitter
src/server/notifications/eventEmitter.ts, src/server/notifications/reportEvents.ts
Add REPORT_CREATED and REPORT_STATUS_CHANGED constants and implement emitReportCreatedNotification for listing and pcListing reports.
Notification service recipient routing & tests
src/server/notifications/service.ts, src/server/notifications/service.test.ts
Respect includeTriggeredBy when deciding whether to remove the triggering actor and add tests verifying moderator/admin/super-admin recipient filtering for report.created.
ReportSubmissionService implementation and usage
src/server/services/report-submission.service.ts
New ReportSubmissionService centralizes creation of listingReport and pcListingReport: sanitizes description, validates target and ownership, prevents duplicates, persists the report, and emits report.created.
Web listing reports router and tests
src/server/api/routers/listingReports.ts, src/server/api/routers/listingReports.test.ts
listingReports router now delegates to ReportSubmissionService.createListingReport. Tests mock sanitize/emitter/prisma and assert sanitized persistence and report.created emission.
Mobile listing reports sanitization and notification
src/server/api/routers/mobile/listingReports.ts, src/server/api/routers/mobile/listingReports.test.ts
mobileListingReports router delegates to the service; tests validate sanitized description, success payload, persistence, and report.created emission.
PC listings sanitization and notification
src/server/api/routers/pcListings.ts, src/server/api/routers/pcListings.test.ts
pcListings router delegates to ReportSubmissionService.createPcListingReport; tests include ReportReason, sanitizeInput mocks, and assert sanitized persistence and report.created emission.
Admin activity link
src/app/admin/dashboard/components/ActivityCard/ReportActivityItem.tsx
Activity link changed to direct /listings/[id] and /pc-listings/[id] routes instead of admin reports query page.

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs:

  • Producdevity/EmuReady#436: Overlaps on notification-service recipient/triggered-by handling and report.created event usage.
  • Producdevity/EmuReady#156: Related edits to PC-listing error helpers in ResourceError used by the new report submission flow.

Suggested labels:
security

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main feature: notifying moderators when reports are submitted, which aligns with the primary objective of the changeset.
Description check ✅ Passed The description covers the main changes, type of change, testing performed, and checklist items. All critical sections are addressed and sufficiently detailed.
Linked Issues check ✅ Passed The PR successfully addresses #390: notifications are sent to moderator-role users and above (including SUPER_ADMIN) after ListingReport creation, using existing notification infrastructure with consistent payloads.
Out of Scope Changes check ✅ Passed All changes align with the stated objectives. The refactoring to ReportSubmissionService, notification infrastructure updates, and description sanitization are directly scoped to implementing report notifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/moderator-report-notifications
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/moderator-report-notifications

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread src/server/notifications/reportEvents.ts Outdated
Comment thread src/server/notifications/service.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/server/services/report-submission.service.ts (1)

89-102: 💤 Low value

Inconsistent error handling pattern between listing and PC listing reports.

createListingReport uses ResourceError.listingReport.* helpers for self-reporting and duplicate detection (lines 38, 50), while createPcListingReport uses AppError.forbidden/conflict directly. Consider using a consistent approach (e.g., ResourceError.pcListingReport.* if available, or standardize on AppError for both).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/server/services/report-submission.service.ts` around lines 89 - 102, The
createPcListingReport path uses AppError.forbidden and AppError.conflict while
createListingReport uses ResourceError.listingReport.*; make them consistent by
replacing AppError.forbidden and AppError.conflict in createPcListingReport with
the corresponding ResourceError.pcListingReport.* helpers (e.g.,
ResourceError.pcListingReport.selfReport and
ResourceError.pcListingReport.duplicateReport or the appropriate helper names),
and add/import ResourceError if missing so both createListingReport and
createPcListingReport use the same ResourceError-based pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/server/services/report-submission.service.ts`:
- Around line 89-102: The createPcListingReport path uses AppError.forbidden and
AppError.conflict while createListingReport uses ResourceError.listingReport.*;
make them consistent by replacing AppError.forbidden and AppError.conflict in
createPcListingReport with the corresponding ResourceError.pcListingReport.*
helpers (e.g., ResourceError.pcListingReport.selfReport and
ResourceError.pcListingReport.duplicateReport or the appropriate helper names),
and add/import ResourceError if missing so both createListingReport and
createPcListingReport use the same ResourceError-based pattern.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 9ef1fd07-c568-4f5d-849f-d0937f824146

📥 Commits

Reviewing files that changed from the base of the PR and between 83c3628 and c596f64.

📒 Files selected for processing (12)
  • src/app/admin/dashboard/components/ActivityCard/ReportActivityItem.tsx
  • src/server/api/routers/listingReports.test.ts
  • src/server/api/routers/listingReports.ts
  • src/server/api/routers/mobile/listingReports.test.ts
  • src/server/api/routers/mobile/listingReports.ts
  • src/server/api/routers/pcListings.test.ts
  • src/server/api/routers/pcListings.ts
  • src/server/notifications/eventEmitter.ts
  • src/server/notifications/reportEvents.ts
  • src/server/notifications/service.test.ts
  • src/server/notifications/service.ts
  • src/server/services/report-submission.service.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/server/notifications/service.test.ts
  • src/server/api/routers/listingReports.test.ts
  • src/server/api/routers/pcListings.test.ts

@coderabbitai coderabbitai Bot added the security label Jun 6, 2026
@Producdevity Producdevity merged commit d9d61db into staging Jun 6, 2026
8 checks passed
@Producdevity Producdevity deleted the fix/moderator-report-notifications branch June 6, 2026 18:32
@coderabbitai coderabbitai Bot mentioned this pull request Jun 8, 2026
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: send notification to SUPER_ADMIN users when a listing is reported

1 participant