silentzco / statamic-akismet

4 stars 2 forks source link

404 viewing spam submission in control panel #52

Open mrcalc opened 3 months ago

mrcalc commented 3 months ago

Current Behavior

Viewing spam submissions in the queue gives a 404 error (Page not found) http://localhost/cp/akismet/queues/contact_us/spam/1721962338.9203

Expected Behavior

Viewing spam submissions in the queue shows the submission.

Possible Solution

This issue seems to be an incompatibility between route binding for {id} and Statamic's use of microtime for IDs.

Spam submissions are stored with the filename created from microtime(true) which contains a dot e.g. 1721962338.9203.yaml.

When this is used in a route with '{id}' it doesn't match id in the route Route::get('{id}', [ShowSpamController::class, '__invoke'])->name('show'); and falls through to the CpController pageNotFound method.

If it is working for other sites, this may be an incompatibility with the environment (see below).

Statamic form submission routes bind on $submission - see Statamic\Http\Controllers\CP\Forms\FormSubmissionsController::show

It seems to work if the route binding uses {submission} instead of {id}. This needs more testing.

// src/routes/cp.php
// Line 28
Route::get('{submission}', [ShowSpamController::class, '__invoke'])->name('show');

Steps to Reproduce

  1. Setup statamic-akismet from readme.md
  2. Submit a form with email address akismet-guaranteed-spam@example.com
  3. Check storage/app/spam/contact_us for new spam submission with the filename based on the microtime of the submission e.g. 1721962338.9203.yaml.
  4. Navigate to http://localhost/cp/akismet/queues/contact_us/spam/1721962338.9203 and see Page not found error. ShowSpamController __invoke is not hit.
  5. Navigate to http://localhost/cp/akismet/queues/contact_us/spam/1721962338 and ShowSpamController __invoke is hit but because there isn't a submission it shows an empty spam submission.

Context (Environment)

Environment Application Name: Test Laravel Version: 10.48.15 PHP Version: 8.2.14 Composer Version: 2.6.6 Environment: local Debug Mode: ENABLED URL: localhost Maintenance Mode: OFF

Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED

Drivers Broadcasting: null Cache: file Database: mysql Logs: stack / daily Mail: smtp Queue: database Session: file

Statamic Addons: 4 Sites: 2 (Test1, Test2) Stache Watcher: Enabled Static Caching: Disabled Version: 5.17.0 PRO

Statamic Addons edalzell/forma: 3.0.1 silentz/akismet: 5.0 stoffelio/statamic-turnstile: 1.2.1 studio1902/statamic-peak-seo: 8.15.3

edalzell commented 3 months ago

Thanks for this, I'll look this week.

edalzell commented 2 months ago

Sorry for the delay but I can't reproduce this. CleanShot 2024-08-22 at 18 14 53@2x

What versions of things are you using? Can you please post the output of php please support:details?

mrcalc commented 2 months ago

Thanks. See Context (Environment) above for support details. I will check that it's not caused by other code on the site.

edalzell commented 2 months ago

See Context (Environment) above for support details

Sigh, I could learn to read.