]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: include base href when opening global search result in new window (#10066)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Tue, 27 May 2025 22:59:17 +0000 (15:59 -0700)
committerGitHub <noreply@github.com>
Tue, 27 May 2025 22:59:17 +0000 (15:59 -0700)
src-ui/src/app/components/app-frame/global-search/global-search.component.spec.ts
src-ui/src/app/components/app-frame/global-search/global-search.component.ts

index 4ff772eb93f168a6dd1b5ec8f044ee16a1ebdffb..eaae4a814fea6af3c5229a3ab7cb72a1a24895e2 100644 (file)
@@ -529,6 +529,17 @@ describe('GlobalSearchComponent', () => {
     expect(dispatchSpy).toHaveBeenCalledTimes(2) // once for keydown, second for click
   })
 
+  it('should support using base href in navigateOrOpenInNewWindow', () => {
+    jest
+      .spyOn(component['locationStrategy'], 'getBaseHref')
+      .mockReturnValue('/base/')
+    const openSpy = jest.spyOn(window, 'open')
+    const event = new Event('click')
+    event['ctrlKey'] = true
+    component.primaryAction(DataType.Document, { id: 1 }, event as any)
+    expect(openSpy).toHaveBeenCalledWith('/base/documents/1', '_blank')
+  })
+
   it('should support title content search and advanced search', () => {
     const qfSpy = jest.spyOn(documentListViewService, 'quickFilter')
     component.query = 'test'
index 8ef466d5b4382b65c35a88b171b9faa01a86c278..36f2ed0b9f7ad97a30ef8af5cd2a6161dee7945a 100644 (file)
@@ -1,4 +1,4 @@
-import { NgTemplateOutlet } from '@angular/common'
+import { LocationStrategy, NgTemplateOutlet } from '@angular/common'
 import {
   Component,
   ElementRef,
@@ -99,7 +99,8 @@ export class GlobalSearchComponent implements OnInit {
     private permissionsService: PermissionsService,
     private toastService: ToastService,
     private hotkeyService: HotKeyService,
-    private settingsService: SettingsService
+    private settingsService: SettingsService,
+    private locationStrategy: LocationStrategy
   ) {
     this.queryDebounce = new Subject<string>()
 
@@ -421,10 +422,13 @@ export class GlobalSearchComponent implements OnInit {
     extras: Object = {}
   ) {
     if (newWindow) {
-      const url = this.router.serializeUrl(
+      const serializedUrl = this.router.serializeUrl(
         this.router.createUrlTree(commands, extras)
       )
-      window.open(url, '_blank')
+      const baseHref = this.locationStrategy.getBaseHref()
+      const fullUrl =
+        baseHref.replace(/\/+$/, '') + '/' + serializedUrl.replace(/^\/+/, '')
+      window.open(fullUrl, '_blank')
     } else {
       this.router.navigate(commands, extras)
     }