* fix: API add and edit answer 400 when the save fails in 13 more controllers, as Users and Notifications do refs #7383
* test: misc API controllers test gives its stub controller a response, as the controllers now set a status refs #7383
---------
Co-authored-by: Isaac Connor <isaac@zoneminder.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* fix: notification and user preference edits write the row in the URL, not an Id from the body refs #7426
* fix: notifications add ignores an Id in the body refs #7426
Follow-up to the numeric field-name guard. FilterComponent::buildFilter() takes
an optional $validFields allow-list, but only EventsController's search index
and MonitorsController (via qualifyFields) used it; the other index/search/
consoleEvents call sites passed none, so a field name was checked only by the
character class, not against a known column set.
Pass array_keys($this->Model->schema()) - the pattern EventsController already
uses - at the remaining sites across Configs, EventData, Events (three), Frames,
Groups, ServerStats, Snapshots, Storage, Tags and UserPreference, so a field
must be a real column of the queried model and an unknown field is a 400 rather
than a MySQL 500. The injection itself is already closed by the numeric
field-name guard; this is defense in depth and consistent error handling.
ServerStatsController's commented-out permission check is left as-is (clients
need the data to render monitors); only the allow-list is added there.
Add tests/php/test_api_filter_fields_enforced.php.
Reported by arpitjain099.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A preference belongs to the user who set it, so ownership is the permission.
The controller instead required System, which got it wrong in both directions:
any System account could read and overwrite another user's preferences, and an
ordinary user could not save their own at all, which is what the montage layout
in montage_common.js does through this controller.
Reads and writes are now scoped to the caller. index lists only the caller's
rows, view, edit and delete refuse a row belonging to someone else, and add pins
UserId to the authenticated user: the client sends its own id in the body, so
taking that on trust let anyone write a preference onto another account. A
System Edit account may still manage anyone's, so an administrator can clear a
broken one.
The find conditions named the table, User_Preferences, where CakePHP wanted the
model alias, UserPreference, so view and edit returned a 500 for everyone. That
is fixed here because it otherwise hides whether the ownership check works.