From cb0e37e76e72984a5fc00ca9cda911fe6079c5f9 Mon Sep 17 00:00:00 2001 From: Wingy Date: Wed, 25 Oct 2023 15:13:05 -0700 Subject: [PATCH] fix(web): fix Theme Custom CSS endpoint requiring the user to be logged in as the server admin (#4633) * fix custom css requiring the user to be the admin and logged in * move theme api to custom endpoint * add e2e test --- cli/src/api/open-api/api.ts | 69 ++++++++++++++++++ mobile/openapi/.openapi-generator/FILES | 3 + mobile/openapi/README.md | Bin 21937 -> 22078 bytes mobile/openapi/doc/ServerInfoApi.md | Bin 8348 -> 9157 bytes mobile/openapi/doc/ServerThemeDto.md | Bin 0 -> 450 bytes mobile/openapi/lib/api.dart | Bin 7165 -> 7201 bytes mobile/openapi/lib/api/server_info_api.dart | Bin 10218 -> 11576 bytes mobile/openapi/lib/api_client.dart | Bin 21380 -> 21460 bytes .../openapi/lib/model/server_theme_dto.dart | Bin 0 -> 2763 bytes mobile/openapi/test/server_info_api_test.dart | Bin 1345 -> 1451 bytes .../openapi/test/server_theme_dto_test.dart | Bin 0 -> 574 bytes server/immich-openapi-specs.json | 32 ++++++++ .../src/domain/server-info/server-info.dto.ts | 5 ++ .../domain/server-info/server-info.service.ts | 5 ++ .../system-config.service.spec.ts | 6 ++ .../system-config/system-config.service.ts | 6 ++ .../controllers/server-info.controller.ts | 7 ++ server/test/e2e/server-info.e2e-spec.ts | 12 +++ web/src/api/open-api/api.ts | 69 ++++++++++++++++++ web/src/routes/custom.css/+server.ts | 6 +- 20 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 mobile/openapi/doc/ServerThemeDto.md create mode 100644 mobile/openapi/lib/model/server_theme_dto.dart create mode 100644 mobile/openapi/test/server_theme_dto_test.dart diff --git a/cli/src/api/open-api/api.ts b/cli/src/api/open-api/api.ts index 0d63ba318..caab7f4b8 100644 --- a/cli/src/api/open-api/api.ts +++ b/cli/src/api/open-api/api.ts @@ -2958,6 +2958,19 @@ export interface ServerStatsResponseDto { */ 'videos': number; } +/** + * + * @export + * @interface ServerThemeDto + */ +export interface ServerThemeDto { + /** + * + * @type {SystemConfigThemeDto} + * @memberof ServerThemeDto + */ + 'theme': SystemConfigThemeDto; +} /** * * @export @@ -13193,6 +13206,35 @@ export const ServerInfoApiAxiosParamCreator = function (configuration?: Configur + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getTheme: async (options: AxiosRequestConfig = {}): Promise => { + const localVarPath = `/server-info/theme`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -13295,6 +13337,15 @@ export const ServerInfoApiFp = function(configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.getSupportedMediaTypes(options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, + /** + * + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getTheme(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getTheme(options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, /** * * @param {*} [options] Override http request option. @@ -13362,6 +13413,14 @@ export const ServerInfoApiFactory = function (configuration?: Configuration, bas getSupportedMediaTypes(options?: AxiosRequestConfig): AxiosPromise { return localVarFp.getSupportedMediaTypes(options).then((request) => request(axios, basePath)); }, + /** + * + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getTheme(options?: AxiosRequestConfig): AxiosPromise { + return localVarFp.getTheme(options).then((request) => request(axios, basePath)); + }, /** * * @param {*} [options] Override http request option. @@ -13440,6 +13499,16 @@ export class ServerInfoApi extends BaseAPI { return ServerInfoApiFp(this.configuration).getSupportedMediaTypes(options).then((request) => request(this.axios, this.basePath)); } + /** + * + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerInfoApi + */ + public getTheme(options?: AxiosRequestConfig) { + return ServerInfoApiFp(this.configuration).getTheme(options).then((request) => request(this.axios, this.basePath)); + } + /** * * @param {*} [options] Override http request option. diff --git a/mobile/openapi/.openapi-generator/FILES b/mobile/openapi/.openapi-generator/FILES index cb9b0ad50..cbad0876c 100644 --- a/mobile/openapi/.openapi-generator/FILES +++ b/mobile/openapi/.openapi-generator/FILES @@ -115,6 +115,7 @@ doc/ServerInfoResponseDto.md doc/ServerMediaTypesResponseDto.md doc/ServerPingResponse.md doc/ServerStatsResponseDto.md +doc/ServerThemeDto.md doc/ServerVersionResponseDto.md doc/SharedLinkApi.md doc/SharedLinkCreateDto.md @@ -285,6 +286,7 @@ lib/model/server_info_response_dto.dart lib/model/server_media_types_response_dto.dart lib/model/server_ping_response.dart lib/model/server_stats_response_dto.dart +lib/model/server_theme_dto.dart lib/model/server_version_response_dto.dart lib/model/shared_link_create_dto.dart lib/model/shared_link_edit_dto.dart @@ -438,6 +440,7 @@ test/server_info_response_dto_test.dart test/server_media_types_response_dto_test.dart test/server_ping_response_test.dart test/server_stats_response_dto_test.dart +test/server_theme_dto_test.dart test/server_version_response_dto_test.dart test/shared_link_api_test.dart test/shared_link_create_dto_test.dart diff --git a/mobile/openapi/README.md b/mobile/openapi/README.md index b4760ae801c735b68b1e1b47d8a3dcae49585c0c..e676dbd88d287ac0f6b92bdcd07910a8c023c88a 100644 GIT binary patch delta 75 zcmdnEnsMJ6#tjuZ9O4#F delta 19 bcmdnDhH>L+#tjuZn{VnYmfyU>XBsB}T~i3% diff --git a/mobile/openapi/doc/ServerInfoApi.md b/mobile/openapi/doc/ServerInfoApi.md index c196bf1081a35775ad901ac6599ef8956f630342..64a373cc030fc46decaf4507c50ecfb59612ea9e 100644 GIT binary patch delta 134 zcmbQ^c+`EvXC{vH)RK^l)ZEm`9~mWBOTa8XMo9>3^BbmvQYtVNT3TFo3c;yGWvNAA t9WEvL3NX3J3x#bb|C9=3g_vb17zt$sN~DRwRBLI)Y9RD)j+e1z0RR!YFg*YO delta 17 ZcmX@=KF4vxXQs`z%)6vEUsHI`1OQ652k-y@ diff --git a/mobile/openapi/doc/ServerThemeDto.md b/mobile/openapi/doc/ServerThemeDto.md new file mode 100644 index 0000000000000000000000000000000000000000..d79f55cf3a5c96f3f450bcb2ae55062e2d1ca8b7 GIT binary patch literal 450 zcma)2!D<3A5WVLs2KJyE$a-&2w(Fr#Mbz7}uwgT5sL6!vR1o^{O}3WWQfNaUyvciS zW?lgl(Cc6;M+Q&T7ULP??uZU+CLxLfo=F?vBf`jlp!*knK+$!b(UFC9fg;1?TEDyc z&9Y}EOztyvbXv#s8QJ0>R@x!F!R`|BQ{&J_8`zRhXhobD>gJ^44N~eaETl{WJCrgp z8!5M!fzdsZ-`m6IZc?_>-|Ce!Wm2UpMAJN^ZGj1vIUP9Jf!lUkRkO`vUN0AkTNvtJ o9eUPzdbOvh#+-%{zSQ&e(?7K-HHF>;vYx+Ld^G&gyc9yb0}d382><{9 literal 0 HcmV?d00001 diff --git a/mobile/openapi/lib/api.dart b/mobile/openapi/lib/api.dart index de69b2894e6d77941a29dcc9d1c9c6014ce7dde0..22c4a23e618ad62357a5cf84b52de141c2be8167 100644 GIT binary patch delta 20 ccmexszR+TWgUIAsakVpiQi~ue-?8~`-lAm23IMX;CkOxl delta 12 TcmdlH^~!(47NyNh8fL5jC>;dq diff --git a/mobile/open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9cX;mj!YwDj=4tCY0x646H)HJZQ1Qa!cc^J{CQB@E{XTC8}OAJGp z<+9s(YB< Km#%tveEa~k{e8dy literal 0 HcmV?d00001 diff --git a/mobile/openapi/test/server_info_api_test.dart b/mobile/openapi/test/server_info_api_test.dart index 17e5e2c5e8f4491d4ff13b2da70e7ef164fb909f..f431f521b06c68b708e57d1b25579aaeef95295d 100644 GIT binary patch delta 44 scmX@ewVHdwEf%4WjMUszmy&!th4j=CFlX|6W@%OkOP`=PVxfh*Q#$9Fb_M0Cp)4gK`zj|SaE_p|{=7y?6V@cfD>-17d z>$r4GRAeY>fhN%HRkKz|w5(OKA(-27$sX=lx#Px0(J3RunwOuv!Ku { const config = await this.configCore.getConfig(); diff --git a/server/src/domain/system-config/system-config.service.spec.ts b/server/src/domain/system-config/system-config.service.spec.ts index 1dcbd013d..f687e4506 100644 --- a/server/src/domain/system-config/system-config.service.spec.ts +++ b/server/src/domain/system-config/system-config.service.spec.ts @@ -298,4 +298,10 @@ describe(SystemConfigService.name, () => { subscription.unsubscribe(); }); }); + + describe('getTheme', () => { + it('should return the default theme', async () => { + await expect(sut.getTheme()).resolves.toEqual(defaults.theme); + }); + }); }); diff --git a/server/src/domain/system-config/system-config.service.ts b/server/src/domain/system-config/system-config.service.ts index 610a1dc29..a44f10c09 100644 --- a/server/src/domain/system-config/system-config.service.ts +++ b/server/src/domain/system-config/system-config.service.ts @@ -1,6 +1,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { JobName } from '../job'; import { CommunicationEvent, ICommunicationRepository, IJobRepository, ISystemConfigRepository } from '../repositories'; +import { SystemConfigThemeDto } from './dto/system-config-theme.dto'; import { SystemConfigDto, mapConfig } from './dto/system-config.dto'; import { SystemConfigTemplateStorageOptionDto } from './response-dto/system-config-template-storage-option.dto'; import { @@ -30,6 +31,11 @@ export class SystemConfigService { return this.core.config$; } + async getTheme(): Promise { + const { theme } = await this.core.getConfig(); + return theme; + } + async getConfig(): Promise { const config = await this.core.getConfig(); return mapConfig(config); diff --git a/server/src/immich/controllers/server-info.controller.ts b/server/src/immich/controllers/server-info.controller.ts index b286329ab..7355583ac 100644 --- a/server/src/immich/controllers/server-info.controller.ts +++ b/server/src/immich/controllers/server-info.controller.ts @@ -6,6 +6,7 @@ import { ServerMediaTypesResponseDto, ServerPingResponse, ServerStatsResponseDto, + ServerThemeDto, ServerVersionResponseDto, } from '@app/domain'; import { Controller, Get } from '@nestjs/common'; @@ -43,6 +44,12 @@ export class ServerInfoController { return this.service.getFeatures(); } + @PublicRoute() + @Get('theme') + getTheme(): Promise { + return this.service.getTheme(); + } + @PublicRoute() @Get('config') getServerConfig(): Promise { diff --git a/server/test/e2e/server-info.e2e-spec.ts b/server/test/e2e/server-info.e2e-spec.ts index cd6afbc07..8f776187f 100644 --- a/server/test/e2e/server-info.e2e-spec.ts +++ b/server/test/e2e/server-info.e2e-spec.ts @@ -155,4 +155,16 @@ describe(`${ServerInfoController.name} (e2e)`, () => { }); }); }); + + describe('GET /server-info/theme', () => { + it('should respond with the server theme', async () => { + const { status, body } = await request(server).get('/server-info/theme'); + expect(status).toBe(200); + expect(body).toEqual({ + theme: { + customCss: '', + }, + }); + }); + }); }); diff --git a/web/src/api/open-api/api.ts b/web/src/api/open-api/api.ts index 0d63ba318..caab7f4b8 100644 --- a/web/src/api/open-api/api.ts +++ b/web/src/api/open-api/api.ts @@ -2958,6 +2958,19 @@ export interface ServerStatsResponseDto { */ 'videos': number; } +/** + * + * @export + * @interface ServerThemeDto + */ +export interface ServerThemeDto { + /** + * + * @type {SystemConfigThemeDto} + * @memberof ServerThemeDto + */ + 'theme': SystemConfigThemeDto; +} /** * * @export @@ -13193,6 +13206,35 @@ export const ServerInfoApiAxiosParamCreator = function (configuration?: Configur + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getTheme: async (options: AxiosRequestConfig = {}): Promise => { + const localVarPath = `/server-info/theme`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -13295,6 +13337,15 @@ export const ServerInfoApiFp = function(configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.getSupportedMediaTypes(options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, + /** + * + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getTheme(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getTheme(options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, /** * * @param {*} [options] Override http request option. @@ -13362,6 +13413,14 @@ export const ServerInfoApiFactory = function (configuration?: Configuration, bas getSupportedMediaTypes(options?: AxiosRequestConfig): AxiosPromise { return localVarFp.getSupportedMediaTypes(options).then((request) => request(axios, basePath)); }, + /** + * + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getTheme(options?: AxiosRequestConfig): AxiosPromise { + return localVarFp.getTheme(options).then((request) => request(axios, basePath)); + }, /** * * @param {*} [options] Override http request option. @@ -13440,6 +13499,16 @@ export class ServerInfoApi extends BaseAPI { return ServerInfoApiFp(this.configuration).getSupportedMediaTypes(options).then((request) => request(this.axios, this.basePath)); } + /** + * + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ServerInfoApi + */ + public getTheme(options?: AxiosRequestConfig) { + return ServerInfoApiFp(this.configuration).getTheme(options).then((request) => request(this.axios, this.basePath)); + } + /** * * @param {*} [options] Override http request option. diff --git a/web/src/routes/custom.css/+server.ts b/web/src/routes/custom.css/+server.ts index acf8e6d10..d5ea304cd 100644 --- a/web/src/routes/custom.css/+server.ts +++ b/web/src/routes/custom.css/+server.ts @@ -1,6 +1,10 @@ import { RequestHandler, text } from '@sveltejs/kit'; export const GET = (async ({ locals: { api } }) => { - const { customCss } = await api.systemConfigApi.getConfig().then((res) => res.data.theme); + const { + data: { + theme: { customCss }, + }, + } = await api.serverInfoApi.getTheme(); return text(customCss, { headers: { 'Content-Type': 'text/css',