mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 06:37:33 +00:00
fix(api): parse path ids with a rowId pipe that answers like an unknown id
RowIdPipe (src/nest/common/row-id.pipe.ts) parses a path param with toRowId. It answers a refused spelling with the route's own not-found answer, so '0x5', '5e0' and 'abc' get what an id that names no row gets. ParseRowIdPipe replaces Nest's ParseIntPipe with the same 400 and message: ParseIntPipe let '-1' and numbers past 2^53 through, and Postgres refuses the latter as out of range. Journey, journey recordings, day import, book design, map, public photo, collections, doc-sync, vacay, atlas and the plugin user-data export declare their ids through it. The upload routes parse in the handler with withRowId, so a refused id takes the existing cleanup path, or carry SpoolCleanupInterceptor (collections).
This commit is contained in:
@@ -4,6 +4,7 @@ import { AddonGuard } from '../addons/addon.guard';
|
||||
import { RequireAddon } from '../addons/require-addon.decorator';
|
||||
import { CurrentUser } from '../auth-core/current-user.decorator';
|
||||
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
|
||||
import { rowId } from '../common/row-id.pipe';
|
||||
import { withRequestContext } from '../database/request-context';
|
||||
import { TripAccessGuard } from '../permissions/trip-access.guard';
|
||||
import { RealtimeService } from '../realtime/realtime.service';
|
||||
@@ -208,11 +209,11 @@ export class DocSyncController {
|
||||
@HttpCode(200)
|
||||
async deleteConnection(
|
||||
@Param('tripId') tripId: string,
|
||||
@Param('connectionId') connectionId: string,
|
||||
@Param('connectionId', rowId('Connection not found')) connectionId: number,
|
||||
@CurrentUser() user: User,
|
||||
) {
|
||||
await this.assertCanManage(tripId, user);
|
||||
const conn = await this.config.getConnection(Number(connectionId));
|
||||
const conn = await this.config.getConnection(connectionId);
|
||||
if (!conn || conn.trip_id !== Number(tripId)) throw new HttpException('Connection not found', 404);
|
||||
// Its bindings go with it (ON DELETE CASCADE), so read them first. Every
|
||||
// subscription TREK registered for one of them is taken down while the
|
||||
@@ -238,12 +239,12 @@ export class DocSyncController {
|
||||
@Get('connections/:connectionId/scopes')
|
||||
async listScopes(
|
||||
@Param('tripId') tripId: string,
|
||||
@Param('connectionId') connectionId: string,
|
||||
@Param('connectionId', rowId('Connection not found')) connectionId: number,
|
||||
@CurrentUser() user: User,
|
||||
@Query('q') q?: string,
|
||||
) {
|
||||
await this.assertCanManage(tripId, user);
|
||||
const conn = await this.config.getConnection(Number(connectionId));
|
||||
const conn = await this.config.getConnection(connectionId);
|
||||
if (!conn || conn.trip_id !== Number(tripId)) throw new HttpException('Connection not found', 404);
|
||||
const provider = this.registry.get(conn.provider_id);
|
||||
if (!provider) throw new HttpException('Provider not available', 400);
|
||||
@@ -255,12 +256,12 @@ export class DocSyncController {
|
||||
@Post('connections/:connectionId/scopes')
|
||||
async createScope(
|
||||
@Param('tripId') tripId: string,
|
||||
@Param('connectionId') connectionId: string,
|
||||
@Param('connectionId', rowId('Connection not found')) connectionId: number,
|
||||
@CurrentUser() user: User,
|
||||
@Body() body: DocsyncScopeCreateDto,
|
||||
) {
|
||||
await this.assertCanManage(tripId, user);
|
||||
const conn = await this.config.getConnection(Number(connectionId));
|
||||
const conn = await this.config.getConnection(connectionId);
|
||||
if (!conn || conn.trip_id !== Number(tripId)) throw new HttpException('Connection not found', 404);
|
||||
const provider = this.registry.get(conn.provider_id);
|
||||
if (!provider) throw new HttpException('Provider not available', 400);
|
||||
@@ -343,13 +344,13 @@ export class DocSyncController {
|
||||
@HttpCode(200)
|
||||
async updateLink(
|
||||
@Param('tripId') tripId: string,
|
||||
@Param('linkId') linkId: string,
|
||||
@Param('linkId', rowId('Link not found')) linkId: number,
|
||||
@CurrentUser() user: User,
|
||||
@Body() body: DocsyncLinkUpdateDto,
|
||||
@Req() req: Request,
|
||||
) {
|
||||
await this.assertCanManage(tripId, user);
|
||||
const link = await this.config.getLink(Number(linkId));
|
||||
const link = await this.config.getLink(linkId);
|
||||
if (!link || link.trip_id !== Number(tripId)) throw new HttpException('Link not found', 404);
|
||||
const updated = await this.config.updateLink(link.id, body);
|
||||
return await this.config.publicLink(updated ?? link, publicOrigin(req));
|
||||
@@ -357,9 +358,13 @@ export class DocSyncController {
|
||||
|
||||
@Delete('links/:linkId')
|
||||
@HttpCode(200)
|
||||
async deleteLink(@Param('tripId') tripId: string, @Param('linkId') linkId: string, @CurrentUser() user: User) {
|
||||
async deleteLink(
|
||||
@Param('tripId') tripId: string,
|
||||
@Param('linkId', rowId('Link not found')) linkId: number,
|
||||
@CurrentUser() user: User,
|
||||
) {
|
||||
await this.assertCanManage(tripId, user);
|
||||
const link = await this.config.getLink(Number(linkId));
|
||||
const link = await this.config.getLink(linkId);
|
||||
if (!link || link.trip_id !== Number(tripId)) throw new HttpException('Link not found', 404);
|
||||
|
||||
const conn = await this.config.getConnection(link.connection_id);
|
||||
@@ -375,8 +380,12 @@ export class DocSyncController {
|
||||
|
||||
@Post('links/:linkId/sync')
|
||||
@HttpCode(200)
|
||||
async syncNow(@Param('tripId') tripId: string, @Param('linkId') linkId: string, @Body() body: DocsyncSyncNowDto) {
|
||||
const link = await this.config.getLink(Number(linkId));
|
||||
async syncNow(
|
||||
@Param('tripId') tripId: string,
|
||||
@Param('linkId', rowId('Link not found')) linkId: number,
|
||||
@Body() body: DocsyncSyncNowDto,
|
||||
) {
|
||||
const link = await this.config.getLink(linkId);
|
||||
if (!link || link.trip_id !== Number(tripId)) throw new HttpException('Link not found', 404);
|
||||
// An orphaned binding stays orphaned: its credential belongs to somebody who
|
||||
// is no longer on this trip. The run itself would stand down as well; this
|
||||
@@ -413,12 +422,12 @@ export class DocSyncController {
|
||||
@HttpCode(200)
|
||||
async resolve(
|
||||
@Param('tripId') tripId: string,
|
||||
@Param('itemId') itemId: string,
|
||||
@Param('itemId', rowId('Item is not in conflict', 400)) itemId: number,
|
||||
@CurrentUser() user: User,
|
||||
@Body() body: DocsyncResolveConflictDto,
|
||||
) {
|
||||
await this.assertCanManage(tripId, user);
|
||||
const ok = await this.sync.resolveConflict(Number(itemId), body.keep, Number(tripId));
|
||||
const ok = await this.sync.resolveConflict(itemId, body.keep, Number(tripId));
|
||||
if (!ok) throw new HttpException('Item is not in conflict', 400);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user