From b8b3c487d48f1f0cf7767aa6663932a9e356f754 Mon Sep 17 00:00:00 2001 From: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> Date: Fri, 29 Mar 2024 04:19:05 +0100 Subject: [PATCH] fix(server): map style not being available for shared assets (#8341) * fix map style not being available for shared assets * add e2e test --- e2e/src/api/specs/system-config.e2e-spec.ts | 18 +++++++++++++++++- .../controllers/system-config.controller.ts | 3 ++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/e2e/src/api/specs/system-config.e2e-spec.ts b/e2e/src/api/specs/system-config.e2e-spec.ts index 8cf389134b..04cfec91e0 100644 --- a/e2e/src/api/specs/system-config.e2e-spec.ts +++ b/e2e/src/api/specs/system-config.e2e-spec.ts @@ -1,4 +1,4 @@ -import { LoginResponseDto, getConfig } from '@immich/sdk'; +import { AssetFileUploadResponseDto, LoginResponseDto, SharedLinkType, getConfig } from '@immich/sdk'; import { createUserDto } from 'src/fixtures'; import { errorDto } from 'src/responses'; import { app, asBearerAuth, utils } from 'src/utils'; @@ -10,11 +10,14 @@ const getSystemConfig = (accessToken: string) => getConfig({ headers: asBearerAu describe('/system-config', () => { let admin: LoginResponseDto; let nonAdmin: LoginResponseDto; + let asset: AssetFileUploadResponseDto; beforeAll(async () => { await utils.resetDatabase(); admin = await utils.adminSetup(); nonAdmin = await utils.userSetup(admin.accessToken, createUserDto.user1); + + asset = await utils.createAsset(admin.accessToken); }); describe('GET /system-config/map/style.json', () => { @@ -24,6 +27,19 @@ describe('/system-config', () => { expect(body).toEqual(errorDto.unauthorized); }); + it('should allow shared link access', async () => { + const sharedLink = await utils.createSharedLink(admin.accessToken, { + type: SharedLinkType.Individual, + assetIds: [asset.id], + }); + const { status, body } = await request(app) + .get(`/system-config/map/style.json?key=${sharedLink.key}`) + .query({ theme: 'dark' }); + + expect(status).toBe(200); + expect(body).toEqual(expect.objectContaining({ id: 'immich-map-dark' })); + }); + it('should throw an error if a theme is not light or dark', async () => { for (const theme of ['dark1', true, 123, '', null, undefined]) { const { status, body } = await request(app) diff --git a/server/src/controllers/system-config.controller.ts b/server/src/controllers/system-config.controller.ts index 1fb9dfbea8..0b46b82a51 100644 --- a/server/src/controllers/system-config.controller.ts +++ b/server/src/controllers/system-config.controller.ts @@ -1,7 +1,7 @@ import { Body, Controller, Get, Put, Query } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { MapThemeDto, SystemConfigDto, SystemConfigTemplateStorageOptionDto } from 'src/dtos/system-config.dto'; -import { AdminRoute, Authenticated } from 'src/middleware/auth.guard'; +import { AdminRoute, Authenticated, SharedLinkRoute } from 'src/middleware/auth.guard'; import { SystemConfigService } from 'src/services/system-config.service'; @ApiTags('System Config') @@ -31,6 +31,7 @@ export class SystemConfigController { } @AdminRoute(false) + @SharedLinkRoute() @Get('map/style.json') getMapStyle(@Query() dto: MapThemeDto) { return this.service.getMapStyle(dto.theme);