Commit Graph
15 Commits
Author SHA1 Message Date
Parsa Aghayi 99f786265e Let the admin panel manage services, skills and testimonials
These three had read endpoints or nothing at all, so their content could only
be changed by hand in the database. All writes are admin-only and rate
limited like the existing admin routes.

Testimonials are the awkward one: the migration that collapsed the legacy
per-locale tables into JSON columns deliberately skipped them, so they still
live in a child table. Testimonial therefore exposes a translations accessor
to present the same translations[key][locale] shape as Service and Skill,
which is what the generic resource form binds to. Reading the child relation
has to go through getRelation(), since a plain $this->translations inside an
accessor of that name re-enters the accessor and silently yields nulls.

The store requests now mark the NOT NULL columns as required. Leaving them
nullable let a bad payload reach the database and come back as a 500 instead
of a 422, and about_me_id is additionally a cascading foreign key.

Also registers the three resources with the admin read endpoint so the panel
can list them, eager loading the relations their forms need.
2026-10-01 18:19:32 -04:00
Parsa Aghayi 6b03c0fbc3 Add a locked-down image upload endpoint for the admin panel
Posts, projects and about-me all carry an image column that could only ever
be filled by typing a URL by hand, so every featured image in the database is
still a placeholder. Uploads are the missing half of content management.

Filenames are generated rather than reused from the client, which is what
keeps a double extension or a path traversal out of a web-served directory.
The upload surface is restricted to raster formats (no SVG, which can carry
script) with a size and dimension ceiling, and throttled at 12/min against
the general admin API's 30/min because an upload costs far more than a JSON
write.

Routes move to per-feature files registered from bootstrap/app.php, since
api.php had become a chokepoint for parallel work on this repo.
2026-10-01 17:41:49 -04:00
Parsa Aghayi 5ae1d1a632 Eager-load relations the admin read API returns
Edit forms are populated from a single request, so posts need their tags and
projects their category attached; otherwise the tag multi-select and category
picker come back empty.
2026-10-01 16:00:06 -04:00
Parsa Aghayi 3f386c7be8 Add the admin content API the CMS needs
Two gaps blocked building the admin panel:

About-me writes could only set the image. Title and description live in the
JSON translations column and were unreachable from the API, so the homepage
bio could never be edited through the app. Accept title_fa/title_en/
description_fa/description_en on both About Me form requests and write them
per locale through setTranslation().

Editing also needs raw rows. The public project and about-me endpoints only
return display-oriented payloads - one translated title, reshaped image
arrays, no second locale - which is not enough to populate a form. Add
GET /api/admin/resources/{resource} behind the same auth:sanctum + admin
middleware as the write routes, returning stored rows including every locale,
plus a public GET /api/website/project-categories so project forms have a
category picker.

Covered by AdminResourceReadTest: anonymous and non-admin callers are
rejected for every resource, unknown resource names 404, and project rows
expose both locales.
2026-10-01 15:28:23 -04:00
root 8b834189a4 Close anonymous write access to the public API and repair the broken test suite
Every mutating endpoint was reachable without authentication, so any visitor
could create, edit or delete posts, categories, tags, projects and about-me
records on the live site.

Security
- Split routes into an anonymous read-only group and a write group gated by
  `auth:sanctum` + a new `admin` middleware.
- Add `is_admin` to users; Sanctum token support on the User model.
- Add AuthController (login / me / logout). The Sanctum token is delivered in
  an httpOnly cookie and never returned in the JSON body, because the admin
  panel reaches the API through a Next.js server-side proxy that breaks
  Sanctum's first-party domain detection.
- AuthenticateAdminPanelSession promotes that cookie to a bearer header so
  Sanctum's normal validation, expiry and revocation still apply.
- Remove the unauthenticated `/user/{id}` route, which exposed user emails.
- Non-admin accounts are refused at login and the failure shape is identical
  to a bad password, so the endpoint cannot enumerate accounts.
- Fix `Route [login] not defined`: a non-JSON unauthenticated request resolved
  a route that does not exist in this API-only app and returned 500.
- Reject invalid list query parameters with 422 instead of 500, and cap
  per_page at 50 (`?per_page=100000` previously dumped whole tables).

Correctness
- Make the translation migration portable. It used MySQL-only JSON_OBJECTAGG,
  which aborted all 29 tests during migration; the data collapse now runs in
  PHP so it works on MySQL, MariaDB and SQLite.
- Add HasJsonTranslations trait providing the missing setTranslation(), which
  made project create/update return 500, and replace five copy-pasted
  getTranslation()/hasTranslation() bodies.
- Make posts.excerpt nullable to match StorePostRequest; omitting an excerpt
  was a guaranteed SQL integrity error.
- Route the AboutMeController CRUD methods that existed but were never
  registered.
- CategoryTest omitted a required description; fixed the test, the existing
  schema and validation already agreed.

Tests: 83 passing / 126 assertions (was 29 failing / 0 assertions)
2026-10-01 14:35:34 -04:00
parsa aghaei afb202f333 3.1-3.6: install l5-swagger, add @OA annotations to all controllers 2026-06-23 18:34:20 +03:30
parsa aghaei db7ce880a0 2.1-2.4: install spatie/laravel-translatable, migrate to JSON, update models & controllers 2026-06-23 18:31:51 +03:30
parsa aghaei 28c7a317e5 1.2: restructure controllers to Api/ prefix and update routes 2026-06-23 18:09:15 +03:30
parsa aghaei cbcccfcbf8 1.1: remove dead code - old models and controllers 2026-06-23 18:07:38 +03:30
parsa aghaei f3568ab277 0.1: replace Request with FormRequest in all controllers 2026-06-23 18:04:57 +03:30
parsa aghaei 6c834607bd multilanguage updated 2024-11-03 16:01:47 +03:30
parsa aghaei 027d1090df internationalization added and backend updated until services 2024-10-23 19:06:12 +03:30
parsa aghaei 9bcf1fb0eb sort and pagination added 2024-10-14 16:22:36 +03:30
parsa aghaei d98bc7bbb0 blog api created 2024-10-13 20:16:08 +03:30
parsa aghaei bd92c3e3fc initial 2024-09-25 13:05:18 +03:30