mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Fix: handle errors for trash actions and only show documents user can restore or delete (#7119)
This commit is contained in:
@@ -1437,7 +1437,7 @@
|
||||
</context-group>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">80</context>
|
||||
<context context-type="linenumber">86</context>
|
||||
</context-group>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/users-groups/users-groups.component.html</context>
|
||||
@@ -2153,7 +2153,7 @@
|
||||
</context-group>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">74</context>
|
||||
<context context-type="linenumber">80</context>
|
||||
</context-group>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/manage/management-list/management-list.component.ts</context>
|
||||
@@ -2179,7 +2179,7 @@
|
||||
</context-group>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">78</context>
|
||||
<context context-type="linenumber">84</context>
|
||||
</context-group>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/users-groups/users-groups.component.ts</context>
|
||||
@@ -2214,42 +2214,74 @@
|
||||
<source>Document deleted</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">63</context>
|
||||
<context context-type="linenumber">64</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="7295637485862454066" datatype="html">
|
||||
<source>Error deleting document</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">69</context>
|
||||
</context-group>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>
|
||||
<context context-type="linenumber">799</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="7266264608936522311" datatype="html">
|
||||
<source>This operation will permanently delete the selected documents.</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">76</context>
|
||||
<context context-type="linenumber">82</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="6804051092296228130" datatype="html">
|
||||
<source>This operation will permanently delete all documents in the trash.</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">77</context>
|
||||
<context context-type="linenumber">83</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="6996183233986182894" datatype="html">
|
||||
<source>Document(s) deleted</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">87</context>
|
||||
<context context-type="linenumber">94</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="6962724852893361467" datatype="html">
|
||||
<source>Error deleting document(s)</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">101</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="7534569062269274401" datatype="html">
|
||||
<source>Document restored</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">97</context>
|
||||
<context context-type="linenumber">113</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="9136016619414048201" datatype="html">
|
||||
<source>Error restoring document</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">117</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="960063472770266304" datatype="html">
|
||||
<source>Document(s) restored</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">106</context>
|
||||
<context context-type="linenumber">127</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="8405416976953346141" datatype="html">
|
||||
<source>Error restoring document(s)</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/admin/trash/trash.component.ts</context>
|
||||
<context context-type="linenumber">133</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="8119815638230251386" datatype="html">
|
||||
@@ -6073,13 +6105,6 @@
|
||||
<context context-type="linenumber">716</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="7295637485862454066" datatype="html">
|
||||
<source>Error deleting document</source>
|
||||
<context-group purpose="location">
|
||||
<context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>
|
||||
<context context-type="linenumber">799</context>
|
||||
</context-group>
|
||||
</trans-unit>
|
||||
<trans-unit id="619486176823357521" datatype="html">
|
||||
<source>Reprocess confirm</source>
|
||||
<context-group purpose="location">
|
||||
|
@@ -11,10 +11,11 @@ import {
|
||||
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
||||
import { TrashService } from 'src/app/services/trash.service'
|
||||
import { of } from 'rxjs'
|
||||
import { of, throwError } from 'rxjs'
|
||||
import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component'
|
||||
import { By } from '@angular/platform-browser'
|
||||
import { SafeHtmlPipe } from 'src/app/pipes/safehtml.pipe'
|
||||
import { ToastService } from 'src/app/services/toast.service'
|
||||
|
||||
const documentsInTrash = [
|
||||
{
|
||||
@@ -36,6 +37,7 @@ describe('TrashComponent', () => {
|
||||
let fixture: ComponentFixture<TrashComponent>
|
||||
let trashService: TrashService
|
||||
let modalService: NgbModal
|
||||
let toastService: ToastService
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
@@ -58,6 +60,7 @@ describe('TrashComponent', () => {
|
||||
fixture = TestBed.createComponent(TrashComponent)
|
||||
trashService = TestBed.inject(TrashService)
|
||||
modalService = TestBed.inject(NgbModal)
|
||||
toastService = TestBed.inject(ToastService)
|
||||
component = fixture.componentInstance
|
||||
fixture.detectChanges()
|
||||
})
|
||||
@@ -76,12 +79,20 @@ describe('TrashComponent', () => {
|
||||
expect(component.documentsInTrash).toEqual(documentsInTrash)
|
||||
})
|
||||
|
||||
it('should support delete document', () => {
|
||||
it('should support delete document, show error if needed', () => {
|
||||
const trashSpy = jest.spyOn(trashService, 'emptyTrash')
|
||||
let modal
|
||||
modalService.activeInstances.subscribe((instances) => {
|
||||
modal = instances[0]
|
||||
})
|
||||
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
||||
|
||||
// fail first
|
||||
trashSpy.mockReturnValue(throwError(() => 'Error'))
|
||||
component.delete(documentsInTrash[0])
|
||||
modal.componentInstance.confirmClicked.next()
|
||||
expect(toastErrorSpy).toHaveBeenCalled()
|
||||
|
||||
trashSpy.mockReturnValue(of('OK'))
|
||||
component.delete(documentsInTrash[0])
|
||||
expect(modal).toBeDefined()
|
||||
@@ -89,12 +100,20 @@ describe('TrashComponent', () => {
|
||||
expect(trashSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should support empty trash', () => {
|
||||
it('should support empty trash, show error if needed', () => {
|
||||
const trashSpy = jest.spyOn(trashService, 'emptyTrash')
|
||||
let modal
|
||||
modalService.activeInstances.subscribe((instances) => {
|
||||
modal = instances[instances.length - 1]
|
||||
})
|
||||
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
||||
|
||||
// fail first
|
||||
trashSpy.mockReturnValue(throwError(() => 'Error'))
|
||||
component.emptyTrash()
|
||||
modal.componentInstance.confirmClicked.next()
|
||||
expect(toastErrorSpy).toHaveBeenCalled()
|
||||
|
||||
trashSpy.mockReturnValue(of('OK'))
|
||||
component.emptyTrash()
|
||||
expect(modal).toBeDefined()
|
||||
@@ -106,18 +125,34 @@ describe('TrashComponent', () => {
|
||||
expect(trashSpy).toHaveBeenCalledWith([1, 2])
|
||||
})
|
||||
|
||||
it('should support restore document', () => {
|
||||
it('should support restore document, show error if needed', () => {
|
||||
const restoreSpy = jest.spyOn(trashService, 'restoreDocuments')
|
||||
const reloadSpy = jest.spyOn(component, 'reload')
|
||||
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
||||
|
||||
// fail first
|
||||
restoreSpy.mockReturnValue(throwError(() => 'Error'))
|
||||
component.restore(documentsInTrash[0])
|
||||
expect(toastErrorSpy).toHaveBeenCalled()
|
||||
expect(reloadSpy).not.toHaveBeenCalled()
|
||||
|
||||
restoreSpy.mockReturnValue(of('OK'))
|
||||
component.restore(documentsInTrash[0])
|
||||
expect(restoreSpy).toHaveBeenCalledWith([documentsInTrash[0].id])
|
||||
expect(reloadSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should support restore all documents', () => {
|
||||
it('should support restore all documents, show error if needed', () => {
|
||||
const restoreSpy = jest.spyOn(trashService, 'restoreDocuments')
|
||||
const reloadSpy = jest.spyOn(component, 'reload')
|
||||
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
||||
|
||||
// fail first
|
||||
restoreSpy.mockReturnValue(throwError(() => 'Error'))
|
||||
component.restoreAll()
|
||||
expect(toastErrorSpy).toHaveBeenCalled()
|
||||
expect(reloadSpy).not.toHaveBeenCalled()
|
||||
|
||||
restoreSpy.mockReturnValue(of('OK'))
|
||||
component.restoreAll()
|
||||
expect(restoreSpy).toHaveBeenCalled()
|
||||
|
@@ -59,10 +59,16 @@ export class TrashComponent implements OnDestroy {
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe(() => {
|
||||
modal.componentInstance.buttonsEnabled = false
|
||||
this.trashService.emptyTrash([document.id]).subscribe(() => {
|
||||
this.toastService.showInfo($localize`Document deleted`)
|
||||
modal.close()
|
||||
this.reload()
|
||||
this.trashService.emptyTrash([document.id]).subscribe({
|
||||
next: () => {
|
||||
this.toastService.showInfo($localize`Document deleted`)
|
||||
modal.close()
|
||||
this.reload()
|
||||
},
|
||||
error: (err) => {
|
||||
this.toastService.showError($localize`Error deleting document`, err)
|
||||
modal.close()
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -83,29 +89,51 @@ export class TrashComponent implements OnDestroy {
|
||||
.subscribe(() => {
|
||||
this.trashService
|
||||
.emptyTrash(documents ? Array.from(documents) : null)
|
||||
.subscribe(() => {
|
||||
this.toastService.showInfo($localize`Document(s) deleted`)
|
||||
this.allToggled = false
|
||||
modal.close()
|
||||
this.reload()
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.toastService.showInfo($localize`Document(s) deleted`)
|
||||
this.allToggled = false
|
||||
modal.close()
|
||||
this.reload()
|
||||
},
|
||||
error: (err) => {
|
||||
this.toastService.showError(
|
||||
$localize`Error deleting document(s)`,
|
||||
err
|
||||
)
|
||||
modal.close()
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
restore(document: Document) {
|
||||
this.trashService.restoreDocuments([document.id]).subscribe(() => {
|
||||
this.toastService.showInfo($localize`Document restored`)
|
||||
this.reload()
|
||||
this.trashService.restoreDocuments([document.id]).subscribe({
|
||||
next: () => {
|
||||
this.toastService.showInfo($localize`Document restored`)
|
||||
this.reload()
|
||||
},
|
||||
error: (err) => {
|
||||
this.toastService.showError($localize`Error restoring document`, err)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
restoreAll(documents: Set<number> = null) {
|
||||
this.trashService
|
||||
.restoreDocuments(documents ? Array.from(documents) : null)
|
||||
.subscribe(() => {
|
||||
this.toastService.showInfo($localize`Document(s) restored`)
|
||||
this.allToggled = false
|
||||
this.reload()
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.toastService.showInfo($localize`Document(s) restored`)
|
||||
this.allToggled = false
|
||||
this.reload()
|
||||
},
|
||||
error: (err) => {
|
||||
this.toastService.showError(
|
||||
$localize`Error restoring document(s)`,
|
||||
err
|
||||
)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user