Create Clear CloudFlare Cache Button #41

Open
opened 2024-01-14 14:41:43 -06:00 by jimmyb · 1 comment
Owner

DB Administrators can upload new game boxart from the admin edit game page, but Cloudflare may continue serving the old cached image after the S3 object changes. Staff need a safe admin action that purges the relevant public boxart URL from Cloudflare so they can verify the new image without waiting for cache expiration.

Cloudflare supports purging cached content by URL through its Cache API (POST /client/v4/zones/{zone_id}/purge_cache with a files payload), so the research portion of the original issue is confirmed. The current Laravel checkout already builds game boxart URLs from config('media.public_assets_url') plus config('media.games.boxart.path'), and the admin game edit page displays the current boxart preview next to the boxart upload field. This issue tracks adding the Cloudflare purge integration and a clear, authorized button on that edit page.

Scope

  • Cloudflare cache purge integration for a single game's current boxart URL.
  • Admin edit game page action/button for clearing cached boxart.
  • Configuration for Cloudflare zone ID and API token, without hard-coding secrets.
  • Server-side request handling that builds the same public boxart URL the site renders.
  • Success, failure, and not-configured feedback for staff.
  • Authorization limited to staff roles that can edit games or otherwise manage game assets.
  • Audit/activity logging for cache purge attempts and outcomes.
  • Tests using mocked HTTP responses rather than real Cloudflare calls.

Acceptance Criteria

  • Authorized staff can click a clear-cache button from admin.games.edit for a game with boxart.
  • The purge request targets the exact public boxart URL generated from the app's media configuration.
  • The integration calls Cloudflare's zone cache purge endpoint with the configured zone ID and bearer token.
  • The request purges only the affected boxart URL, not the entire Cloudflare zone.
  • A successful purge returns the user to the game edit page with clear success feedback.
  • A Cloudflare API failure returns the user to the game edit page with clear error feedback and does not modify the game record.
  • Missing Cloudflare configuration disables the action or returns a clear not-configured message rather than failing silently.
  • Games without boxart do not show an actionable purge button or return a clear no-boxart message.
  • Non-staff users and staff without the required game-management role cannot trigger the purge endpoint.
  • Purge attempts are logged with game ID, boxart URL, actor, result, and enough error context for troubleshooting without leaking secrets.
  • The button follows existing admin UI patterns, light/dark mode, and submit/loading-state conventions.

Test Coverage Required

  • Feature tests confirming authorized game admins can trigger a boxart cache purge.
  • HTTP fake tests asserting the Cloudflare request uses the expected endpoint, bearer token, zone ID, and files payload.
  • Feature tests confirming successful purges redirect back to the edit page with success feedback.
  • Feature tests confirming Cloudflare errors redirect back with error feedback and leave the game unchanged.
  • Tests confirming missing Cloudflare config is handled safely.
  • Tests confirming games without boxart cannot submit a misleading purge request.
  • Authorization tests confirming non-staff or insufficient-role users cannot access the purge route/action.
  • View tests or feature assertions confirming the button appears on the admin edit game page only when appropriate.
  • Logging/activity assertions where practical for successful and failed purge attempts.
  • Tests should use Pest and focused feature coverage with Laravel HTTP fakes.
  • Run the focused affected tests, then run vendor/bin/pint --dirty --format agent before closing the issue.

Progress Checklist

  • Cloudflare supports cache purge by URL through its API
  • Admin game edit page exists
  • Admin game edit page shows the current boxart preview
  • Admin game update flow uploads replacement boxart to S3-backed assets/boxart
  • Media config builds public boxart URLs from MVGL_PUBLIC_ASSETS_URL and MVGL_GAME_BOXART_PATH
  • Add Cloudflare cache configuration keys for zone ID and API token
  • Add a service/action for purging a single boxart URL through Cloudflare
  • Add an authorized route/controller action for game boxart cache purge
  • Add the clear-cache button to the admin edit game page
  • Handle success, failure, no-boxart, and not-configured states in the UI
  • Log purge attempts without exposing Cloudflare credentials
  • Add tests for HTTP payloads, authorization, UI visibility, success/failure feedback, and missing config
  • Confirm DB Administrators can verify newly uploaded boxart after clearing the cache
DB Administrators can upload new game boxart from the admin edit game page, but Cloudflare may continue serving the old cached image after the S3 object changes. Staff need a safe admin action that purges the relevant public boxart URL from Cloudflare so they can verify the new image without waiting for cache expiration. Cloudflare supports purging cached content by URL through its Cache API (`POST /client/v4/zones/{zone_id}/purge_cache` with a `files` payload), so the research portion of the original issue is confirmed. The current Laravel checkout already builds game boxart URLs from `config('media.public_assets_url')` plus `config('media.games.boxart.path')`, and the admin game edit page displays the current boxart preview next to the boxart upload field. This issue tracks adding the Cloudflare purge integration and a clear, authorized button on that edit page. ## Scope - Cloudflare cache purge integration for a single game's current boxart URL. - Admin edit game page action/button for clearing cached boxart. - Configuration for Cloudflare zone ID and API token, without hard-coding secrets. - Server-side request handling that builds the same public boxart URL the site renders. - Success, failure, and not-configured feedback for staff. - Authorization limited to staff roles that can edit games or otherwise manage game assets. - Audit/activity logging for cache purge attempts and outcomes. - Tests using mocked HTTP responses rather than real Cloudflare calls. ## Acceptance Criteria - Authorized staff can click a clear-cache button from `admin.games.edit` for a game with boxart. - The purge request targets the exact public boxart URL generated from the app's media configuration. - The integration calls Cloudflare's zone cache purge endpoint with the configured zone ID and bearer token. - The request purges only the affected boxart URL, not the entire Cloudflare zone. - A successful purge returns the user to the game edit page with clear success feedback. - A Cloudflare API failure returns the user to the game edit page with clear error feedback and does not modify the game record. - Missing Cloudflare configuration disables the action or returns a clear not-configured message rather than failing silently. - Games without boxart do not show an actionable purge button or return a clear no-boxart message. - Non-staff users and staff without the required game-management role cannot trigger the purge endpoint. - Purge attempts are logged with game ID, boxart URL, actor, result, and enough error context for troubleshooting without leaking secrets. - The button follows existing admin UI patterns, light/dark mode, and submit/loading-state conventions. ## Test Coverage Required - Feature tests confirming authorized game admins can trigger a boxart cache purge. - HTTP fake tests asserting the Cloudflare request uses the expected endpoint, bearer token, zone ID, and `files` payload. - Feature tests confirming successful purges redirect back to the edit page with success feedback. - Feature tests confirming Cloudflare errors redirect back with error feedback and leave the game unchanged. - Tests confirming missing Cloudflare config is handled safely. - Tests confirming games without boxart cannot submit a misleading purge request. - Authorization tests confirming non-staff or insufficient-role users cannot access the purge route/action. - View tests or feature assertions confirming the button appears on the admin edit game page only when appropriate. - Logging/activity assertions where practical for successful and failed purge attempts. - Tests should use Pest and focused feature coverage with Laravel HTTP fakes. - Run the focused affected tests, then run `vendor/bin/pint --dirty --format agent` before closing the issue. ## Progress Checklist - [x] Cloudflare supports cache purge by URL through its API - [x] Admin game edit page exists - [x] Admin game edit page shows the current boxart preview - [x] Admin game update flow uploads replacement boxart to S3-backed `assets/boxart` - [x] Media config builds public boxart URLs from `MVGL_PUBLIC_ASSETS_URL` and `MVGL_GAME_BOXART_PATH` - [ ] Add Cloudflare cache configuration keys for zone ID and API token - [ ] Add a service/action for purging a single boxart URL through Cloudflare - [ ] Add an authorized route/controller action for game boxart cache purge - [ ] Add the clear-cache button to the admin edit game page - [ ] Handle success, failure, no-boxart, and not-configured states in the UI - [ ] Log purge attempts without exposing Cloudflare credentials - [ ] Add tests for HTTP payloads, authorization, UI visibility, success/failure feedback, and missing config - [ ] Confirm DB Administrators can verify newly uploaded boxart after clearing the cache
Codex self-assigned this 2026-10-14 13:08:15 -05:00
Member

Progress update for issue #41:

Implemented the boxart cache-clearing feature on the dedicated local branch codex/issue-41-clear-cloudflare-boxart-cache (commit 4b3146f5). The work is isolated from master; no PR has been created, and the branch has not been pushed or deployed.

Completed:

  • Cloudflare zone ID and API token configuration, with blank example environment entries.
  • A single-URL Cloudflare purge service using bearer authentication, a 10-second timeout, and explicit API-success validation.
  • A CSRF-protected POST action limited to game-management roles 1–3, with GamePolicy authorization and admin mutation throttling.
  • Server-side boxart URL generation through the existing GameMediaUrls helper; client-supplied URLs and pending game edits are ignored.
  • Success, API failure, connection failure, missing configuration, and missing boxart feedback.
  • Activity logging with actor, game ID, boxart URL, outcome, HTTP status, and sanitized error codes; credentials and raw API responses are excluded.
  • An independent cache-clearing form beside the boxart preview, using the existing loading-state component. The button uses Cloudflare orange and the fa-brands fa-cloudflare icon to the left of its text.
  • Focused Pest coverage for authorization, exact HTTP payloads, URL variants, failures, audit logging, unchanged game data, soft-deleted games, and UI availability.

Verification:

  • 47 focused and affected game-edit regression tests passed during implementation; the latest focused run after the button updates passed all 27 tests.
  • Pint, PHPStan, frontend asset build, and whitespace checks passed.
  • Browser checks passed for independent form submission and loading feedback in desktop light/dark and mobile layouts.
  • Live credential verification reported an active token. The configured token and zone ID match between the local production-shaped and development environment files.
  • A real single-boxart purge through the isolated app route returned Cloudflare HTTP 200 with success feedback and an audit record, without changing the game record. This used transactional SQLite test fixtures and a boxart URL obtained from the public development homepage; it was not a click on a deployed admin button.

Remaining limitation:
The current public boxart URLs point directly to Amazon S3. The tested image returned HTTP 200 with Server: AmazonS3 and no CF-Cache-Status header. Cloudflare accepted the purge, but that does not demonstrate any cached image was removed. For this action to clear boxart cached by Cloudflare, the images must be served through a Cloudflare-proxied hostname and the media URL configuration must target it. End-to-end verification of refreshed boxart through that hostname remains outstanding.

The configured development database connection refused connections during the live check, so the rendered public development page supplied the boxart URL instead. No production database writes or live game edits were performed. The issue remains open and in progress.

Progress update for issue #41: Implemented the boxart cache-clearing feature on the dedicated local branch `codex/issue-41-clear-cloudflare-boxart-cache` (commit `4b3146f5`). The work is isolated from `master`; no PR has been created, and the branch has not been pushed or deployed. Completed: - Cloudflare zone ID and API token configuration, with blank example environment entries. - A single-URL Cloudflare purge service using bearer authentication, a 10-second timeout, and explicit API-success validation. - A CSRF-protected POST action limited to game-management roles 1–3, with GamePolicy authorization and admin mutation throttling. - Server-side boxart URL generation through the existing GameMediaUrls helper; client-supplied URLs and pending game edits are ignored. - Success, API failure, connection failure, missing configuration, and missing boxart feedback. - Activity logging with actor, game ID, boxart URL, outcome, HTTP status, and sanitized error codes; credentials and raw API responses are excluded. - An independent cache-clearing form beside the boxart preview, using the existing loading-state component. The button uses Cloudflare orange and the `fa-brands fa-cloudflare` icon to the left of its text. - Focused Pest coverage for authorization, exact HTTP payloads, URL variants, failures, audit logging, unchanged game data, soft-deleted games, and UI availability. Verification: - 47 focused and affected game-edit regression tests passed during implementation; the latest focused run after the button updates passed all 27 tests. - Pint, PHPStan, frontend asset build, and whitespace checks passed. - Browser checks passed for independent form submission and loading feedback in desktop light/dark and mobile layouts. - Live credential verification reported an active token. The configured token and zone ID match between the local production-shaped and development environment files. - A real single-boxart purge through the isolated app route returned Cloudflare HTTP 200 with success feedback and an audit record, without changing the game record. This used transactional SQLite test fixtures and a boxart URL obtained from the public development homepage; it was not a click on a deployed admin button. Remaining limitation: The current public boxart URLs point directly to Amazon S3. The tested image returned HTTP 200 with `Server: AmazonS3` and no `CF-Cache-Status` header. Cloudflare accepted the purge, but that does not demonstrate any cached image was removed. For this action to clear boxart cached by Cloudflare, the images must be served through a Cloudflare-proxied hostname and the media URL configuration must target it. End-to-end verification of refreshed boxart through that hostname remains outstanding. The configured development database connection refused connections during the live check, so the rendered public development page supplied the boxart URL instead. No production database writes or live game edits were performed. The issue remains open and in progress.
Sign in to join this conversation.
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MyVideoGameList/myvideogamelist.com#41
No description provided.