]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: saved view permissions fixes (#7672)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Tue, 10 Sep 2024 20:33:19 +0000 (13:33 -0700)
committerGitHub <noreply@github.com>
Tue, 10 Sep 2024 20:33:19 +0000 (13:33 -0700)
src-ui/src/app/components/admin/settings/settings.component.html
src-ui/src/app/components/app-frame/app-frame.component.spec.ts
src-ui/src/app/components/app-frame/app-frame.component.ts
src-ui/src/app/services/rest/saved-view.service.spec.ts
src-ui/src/app/services/rest/saved-view.service.ts

index d146b3657b8752a94cbc49de926df864436cd392..5b554690e5380d5cc7a712ce13c4e1af22696c51 100644 (file)
       </ng-template>
     </li>
 
-    <li [ngbNavItem]="SettingsNavIDs.SavedViews">
+    <li [ngbNavItem]="SettingsNavIDs.SavedViews" *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.SavedView }">
       <a ngbNavLink i18n>Saved views</a>
       <ng-template ngbNavContent>
 
index c1b53d63dabf714b0cb195b2e9e63127e8692bdd..1354a187ea44c00044b99a1f282e86f847de0c16 100644 (file)
@@ -115,7 +115,7 @@ describe('AppFrameComponent', () => {
         {
           provide: SavedViewService,
           useValue: {
-            initialize: () => {},
+            reload: () => {},
             listAll: () =>
               of({
                 all: [saved_views.map((v) => v.id)],
@@ -170,7 +170,7 @@ describe('AppFrameComponent', () => {
       .mockReturnValue('Hello World')
     jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
 
-    savedViewSpy = jest.spyOn(savedViewService, 'initialize')
+    savedViewSpy = jest.spyOn(savedViewService, 'reload')
 
     fixture = TestBed.createComponent(AppFrameComponent)
     component = fixture.componentInstance
index 4d4968ea404fc9796e5fa919169b3e1630caefca..df6ac65a20335fed8a189e8e0385795421f3b340 100644 (file)
@@ -73,7 +73,7 @@ export class AppFrameComponent
         PermissionType.SavedView
       )
     ) {
-      this.savedViewService.initialize()
+      this.savedViewService.reload()
     }
   }
 
index 44ee8c05c0326992ae0375cfed30bed0ccd53972..fc2d996a527c5a7a51cb27dc126b81e41dc0133c 100644 (file)
@@ -57,7 +57,7 @@ describe(`Additional service tests for SavedViewService`, () => {
   let settingsService
 
   it('should retrieve saved views and sort them', () => {
-    service.initialize()
+    service.reload()
     const req = httpTestingController.expectOne(
       `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
     )
@@ -70,7 +70,7 @@ describe(`Additional service tests for SavedViewService`, () => {
   })
 
   it('should gracefully handle errors', () => {
-    service.initialize()
+    service.reload()
     const req = httpTestingController.expectOne(
       `${environment.apiBaseUrl}${endpoint}/?page=1&page_size=100000`
     )
index 1b81f20544e89856fabf33a87f476cae13643d06..274522c714e17fff8adc67bb6b8c81ff1a04ed65 100644 (file)
@@ -6,6 +6,7 @@ import { SavedView } from 'src/app/data/saved-view'
 import { AbstractPaperlessService } from './abstract-paperless-service'
 import { SettingsService } from '../settings.service'
 import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
+import { Results } from 'src/app/data/results'
 
 @Injectable({
   providedIn: 'root',
@@ -21,22 +22,31 @@ export class SavedViewService extends AbstractPaperlessService<SavedView> {
     super(http, 'saved_views')
   }
 
-  public initialize() {
-    this.reload()
+  public list(
+    page?: number,
+    pageSize?: number,
+    sortField?: string,
+    sortReverse?: boolean,
+    extraParams?: any
+  ): Observable<Results<SavedView>> {
+    return super.list(page, pageSize, sortField, sortReverse, extraParams).pipe(
+      tap({
+        next: (r) => {
+          this.savedViews = r.results
+          this.loading = false
+          this.settingsService.dashboardIsEmpty =
+            this.dashboardViews.length === 0
+        },
+        error: () => {
+          this.loading = false
+          this.settingsService.dashboardIsEmpty = true
+        },
+      })
+    )
   }
 
-  private reload() {
-    this.listAll().subscribe({
-      next: (r) => {
-        this.savedViews = r.results
-        this.loading = false
-        this.settingsService.dashboardIsEmpty = this.dashboardViews.length === 0
-      },
-      error: () => {
-        this.loading = false
-        this.settingsService.dashboardIsEmpty = true
-      },
-    })
+  public reload() {
+    this.listAll().subscribe()
   }
 
   get allViews() {