Fix: saved view permissions fixes (#7672)

This commit is contained in:
shamoon 2024-09-10 13:33:19 -07:00 committed by GitHub
parent f1559b7108
commit bee963c23d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 20 deletions

View File

@ -332,7 +332,7 @@
</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>

View 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

View File

@ -73,7 +73,7 @@ export class AppFrameComponent
PermissionType.SavedView
)
) {
this.savedViewService.initialize()
this.savedViewService.reload()
}
}

View 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`
)

View 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()
}
private reload() {
this.listAll().subscribe({
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
this.settingsService.dashboardIsEmpty =
this.dashboardViews.length === 0
},
error: () => {
this.loading = false
this.settingsService.dashboardIsEmpty = true
},
})
)
}
public reload() {
this.listAll().subscribe()
}
get allViews() {