mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-20 01:33:22 +00:00
Fix: hide version delete button without global perms (#13735)
This commit is contained in:
+1
@@ -141,6 +141,7 @@
|
||||
i18n-confirmMessage
|
||||
[disabled]="!userIsOwner || !userCanEdit"
|
||||
(confirm)="deleteVersion(version.id)"
|
||||
*pngxIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.Document }"
|
||||
>
|
||||
<span class="visually-hidden" i18n>Delete version</span>
|
||||
</pngx-confirm-button>
|
||||
|
||||
+41
@@ -1,10 +1,16 @@
|
||||
import { DatePipe } from '@angular/common'
|
||||
import { SimpleChange, signal } from '@angular/core'
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||
import { By } from '@angular/platform-browser'
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
||||
import { Subject, of, throwError } from 'rxjs'
|
||||
import { DocumentVersionInfo } from 'src/app/data/document'
|
||||
import {
|
||||
PermissionAction,
|
||||
PermissionsService,
|
||||
PermissionType,
|
||||
} from 'src/app/services/permissions.service'
|
||||
import { DocumentService } from 'src/app/services/rest/document.service'
|
||||
import { SettingsService } from 'src/app/services/settings.service'
|
||||
import { ToastService } from 'src/app/services/toast.service'
|
||||
@@ -31,6 +37,9 @@ describe('DocumentVersionDropdownComponent', () => {
|
||||
let finished$: Subject<{ taskId: string }>
|
||||
let failed$: Subject<{ taskId: string; message?: string }>
|
||||
let modalService: jest.Mocked<Pick<NgbModal, 'open'>>
|
||||
let permissionsService: jest.Mocked<
|
||||
Pick<PermissionsService, 'currentUserCan'>
|
||||
>
|
||||
|
||||
beforeEach(async () => {
|
||||
finished$ = new Subject<{ taskId: string }>()
|
||||
@@ -47,6 +56,9 @@ describe('DocumentVersionDropdownComponent', () => {
|
||||
showError: jest.fn(),
|
||||
showInfo: jest.fn(),
|
||||
}
|
||||
permissionsService = {
|
||||
currentUserCan: jest.fn().mockReturnValue(true),
|
||||
}
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [
|
||||
@@ -73,6 +85,10 @@ describe('DocumentVersionDropdownComponent', () => {
|
||||
provide: NgbModal,
|
||||
useValue: modalService,
|
||||
},
|
||||
{
|
||||
provide: PermissionsService,
|
||||
useValue: permissionsService,
|
||||
},
|
||||
{
|
||||
provide: WebsocketStatusService,
|
||||
useValue: {
|
||||
@@ -143,6 +159,31 @@ describe('DocumentVersionDropdownComponent', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not show version delete buttons without document delete permission', () => {
|
||||
fixture.destroy()
|
||||
permissionsService.currentUserCan.mockReturnValue(false)
|
||||
fixture = TestBed.createComponent(DocumentVersionDropdownComponent)
|
||||
component = fixture.componentInstance
|
||||
component.documentId = 3
|
||||
component.selectedVersionId = 3
|
||||
component.userIsOwner = true
|
||||
component.userCanEdit = true
|
||||
component.versions = [
|
||||
{ id: 3, is_root: true, checksum: 'aaaa' },
|
||||
{ id: 10, is_root: false, checksum: 'bbbb' },
|
||||
]
|
||||
|
||||
fixture.detectChanges()
|
||||
|
||||
expect(permissionsService.currentUserCan).toHaveBeenCalledWith(
|
||||
PermissionAction.Delete,
|
||||
PermissionType.Document
|
||||
)
|
||||
expect(
|
||||
fixture.debugElement.queryAll(By.css('pngx-confirm-button'))
|
||||
).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('beginEditingVersion should set active row and draft label', () => {
|
||||
component.userCanEdit = true
|
||||
component.userIsOwner = true
|
||||
|
||||
+7
-1
@@ -25,6 +25,7 @@ import {
|
||||
tap,
|
||||
} from 'rxjs/operators'
|
||||
import { DocumentVersionInfo } from 'src/app/data/document'
|
||||
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
|
||||
import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
|
||||
import { DocumentService } from 'src/app/services/rest/document.service'
|
||||
import { ToastService } from 'src/app/services/toast.service'
|
||||
@@ -33,6 +34,7 @@ import {
|
||||
WebsocketStatusService,
|
||||
} from 'src/app/services/websocket-status.service'
|
||||
import { ConfirmButtonComponent } from '../../common/confirm-button/confirm-button.component'
|
||||
import { ComponentWithPermissions } from '../../with-permissions/with-permissions.component'
|
||||
import { AddExistingDocumentVersionDialogComponent } from './add-existing-document-version-dialog/add-existing-document-version-dialog.component'
|
||||
|
||||
@Component({
|
||||
@@ -44,11 +46,15 @@ import { AddExistingDocumentVersionDialogComponent } from './add-existing-docume
|
||||
NgbDropdownModule,
|
||||
NgxBootstrapIconsModule,
|
||||
ConfirmButtonComponent,
|
||||
IfPermissionsDirective,
|
||||
SlicePipe,
|
||||
CustomDatePipe,
|
||||
],
|
||||
})
|
||||
export class DocumentVersionDropdownComponent implements OnChanges, OnDestroy {
|
||||
export class DocumentVersionDropdownComponent
|
||||
extends ComponentWithPermissions
|
||||
implements OnChanges, OnDestroy
|
||||
{
|
||||
UploadState = UploadState
|
||||
|
||||
@Input() documentId: number
|
||||
|
||||
Reference in New Issue
Block a user