Feature: app branding (#5357)

This commit is contained in:
shamoon
2024-01-13 11:57:25 -08:00
committed by GitHub
parent 2da5e46386
commit 2a6e79acc8
34 changed files with 675 additions and 118 deletions

View File

@@ -39,4 +39,26 @@ describe('ConfigService', () => {
)
expect(req.request.method).toEqual('PATCH')
})
it('should support upload file with form data', () => {
service.uploadFile(new File([], 'test.png'), 1, 'app_logo').subscribe()
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}config/1/`
)
expect(req.request.method).toEqual('PATCH')
expect(req.request.body).not.toBeNull()
})
it('should not pass string app_logo', () => {
service
.saveConfig({
id: 1,
app_logo: '/logo/foobar.png',
} as PaperlessConfig)
.subscribe()
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}config/1/`
)
expect(req.request.body).toEqual({ id: 1 })
})
})

View File

@@ -20,8 +20,22 @@ export class ConfigService {
}
saveConfig(config: PaperlessConfig): Observable<PaperlessConfig> {
// dont pass string
if (typeof config.app_logo === 'string') delete config.app_logo
return this.http
.patch<PaperlessConfig>(`${this.baseUrl}${config.id}/`, config)
.pipe(first())
}
uploadFile(
file: File,
configID: number,
configKey: string
): Observable<PaperlessConfig> {
let formData = new FormData()
formData.append(configKey, file, file.name)
return this.http
.patch<PaperlessConfig>(`${this.baseUrl}${configID}/`, formData)
.pipe(first())
}
}

View File

@@ -301,4 +301,16 @@ describe('SettingsService', () => {
.expectOne(`${environment.apiBaseUrl}ui_settings/`)
.flush(ui_settings)
})
it('should update environment app title if set', () => {
const settings = Object.assign({}, ui_settings)
settings.settings['app_title'] = 'FooBar'
const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}ui_settings/`
)
req.flush(settings)
expect(environment.appTitle).toEqual('FooBar')
// post for migrate
httpTestingController.expectOne(`${environment.apiBaseUrl}ui_settings/`)
})
})

View File

@@ -270,6 +270,9 @@ export class SettingsService {
first(),
tap((uisettings) => {
Object.assign(this.settings, uisettings.settings)
if (this.get(SETTINGS_KEYS.APP_TITLE)?.length) {
environment.appTitle = this.get(SETTINGS_KEYS.APP_TITLE)
}
this.maybeMigrateSettings()
// to update lang cookie
if (this.settings['language']?.length)