mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +00:00
fix(api): read body, query and handler-parsed ids with toRowId instead of Number() and parseInt
The services and controllers that took an id from a request with Number(), parseInt() or not at all now use toRowId. That covers admin users, notifications (and their limit and offset), trip members and guests, day notes, assignments, memories (photo owner, album link, body photo_id), photos, mail-ingest, the assistant id parsers, dawarich, registration invites, the plugin contribution routes and the collab reply. The accommodation update body is open, so AccommodationsService reads the place and day refs of every stay write with toRowId and answers a refused one with the create schema's 400. AdminService.deleteUser checked the caller with parseInt and deleted with Number(), so an admin could delete their own account by spelling its id in hex; both now use one parse. The OAuth session revoke called Number(id) first and so revoked session 5 for '0x5'; the service now reads the id as sent.
This commit is contained in:
@@ -4,6 +4,7 @@ import { CurrentUser } from '../auth-core/current-user.decorator';
|
||||
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
|
||||
import { DEMO_WRITE_ERROR, isDemoWriteBlocked } from '../common/demo-write';
|
||||
import { ResponseContract } from '../common/response-contract';
|
||||
import { toRowId } from '../common/row-id';
|
||||
import { SpoolCleanupInterceptor } from '../common/spool-cleanup.interceptor';
|
||||
import { BLOCKED_EXTENSIONS, MAX_FILE_SIZE } from '../files/files.constants';
|
||||
import { RequirePermission, TripAccessGuard } from '../permissions/trip-access.guard';
|
||||
@@ -534,13 +535,14 @@ export class CollabController {
|
||||
for (const name of committed) await this.storage.delete('files', name).catch(() => {});
|
||||
throw err;
|
||||
}
|
||||
// The schema took a whole number or its digits; '' is the multipart form's "no reply".
|
||||
const replyTo =
|
||||
body.reply_to === undefined || body.reply_to === '' || body.reply_to === null ? null : Number(body.reply_to);
|
||||
body.reply_to === undefined || body.reply_to === '' || body.reply_to === null ? null : toRowId(body.reply_to);
|
||||
const result = await this.collab.postMessage(
|
||||
tripId,
|
||||
{
|
||||
text,
|
||||
replyTo: Number.isFinite(replyTo as number) ? replyTo : null,
|
||||
replyTo,
|
||||
files: uploaded.map((file) => ({
|
||||
filename: file.filename,
|
||||
originalname: file.originalname,
|
||||
|
||||
Reference in New Issue
Block a user