mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 14:17:31 +00:00
fix(plugins): let a file write past Documents off only for the targets it writes
files.update and files.createLink took any target key in the call as an attachment, also one they never store.
This commit is contained in:
@@ -182,7 +182,11 @@ export class FilesRpc {
|
||||
const file = await this.files.getFileById(fileId, tripId);
|
||||
if (!file) throw new ForbiddenResource(`no file ${fileId} on trip ${tripId}`);
|
||||
const opts = asPayload(params.opts) as { reservation_id?: number; assignment_id?: number; place_id?: number };
|
||||
await this.requireReachable(tripId, file, opts);
|
||||
await this.requireReachable(tripId, file, {
|
||||
reservation_id: opts.reservation_id,
|
||||
assignment_id: opts.assignment_id,
|
||||
place_id: opts.place_id,
|
||||
});
|
||||
// A link target on another trip would otherwise attach this trip's file to it.
|
||||
const foreign = await this.files.findForeignLinkTarget(tripId, opts);
|
||||
if (foreign) throw new ForbiddenResource(`${foreign} does not belong to trip ${tripId}`);
|
||||
@@ -206,7 +210,7 @@ export class FilesRpc {
|
||||
place_id?: number | null;
|
||||
reservation_id?: number | null;
|
||||
};
|
||||
await this.requireReachable(tripId, current, input);
|
||||
await this.requireReachable(tripId, current, { place_id: input.place_id, reservation_id: input.reservation_id });
|
||||
const foreign = await this.files.findForeignLinkTarget(tripId, {
|
||||
reservation_id: input.reservation_id ?? null,
|
||||
place_id: input.place_id ?? null,
|
||||
|
||||
@@ -260,6 +260,10 @@ describe('FilesRpc with Documents off for the trip', () => {
|
||||
expect(
|
||||
await forbidden(host.dispatch(req('files.createLink', { tripId: 1, fileId: 2, opts: {} }), 42)),
|
||||
).toMatchObject({ code: 'RESOURCE_FORBIDDEN' });
|
||||
const unwritten = req('files.update', { tripId: 1, fileId: 2, input: { description: 'x', budget_item_id: 9 } });
|
||||
expect(await forbidden(host.dispatch(unwritten, 42))).toMatchObject({ code: 'RESOURCE_FORBIDDEN' });
|
||||
const unlinked = req('files.createLink', { tripId: 1, fileId: 2, opts: { budget_item_id: 9 } });
|
||||
expect(await forbidden(host.dispatch(unlinked, 42))).toMatchObject({ code: 'RESOURCE_FORBIDDEN' });
|
||||
expect(f.files.updateFile).not.toHaveBeenCalled();
|
||||
|
||||
const attach = req('files.update', { tripId: 1, fileId: 2, input: { reservation_id: 4 } });
|
||||
|
||||
Reference in New Issue
Block a user