]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Hide delete button on detail page if no perms, fix error display & allow retry confir...
authorshamoon <4887959+shamoon@users.noreply.github.com>
Tue, 4 Apr 2023 23:16:17 +0000 (16:16 -0700)
committerGitHub <noreply@github.com>
Tue, 4 Apr 2023 23:16:17 +0000 (16:16 -0700)
src-ui/src/app/components/document-detail/document-detail.component.html
src-ui/src/app/components/document-detail/document-detail.component.ts

index c88dc7e98703593ce0d7b450a078b550649c8d1a..cad0f715af4a2254137a9790ba0aab573e77c1c8 100644 (file)
@@ -5,7 +5,7 @@
       <div class="input-group-text" i18n>of {{previewNumPages}}</div>
     </div>
 
-    <button type="button" class="btn btn-sm btn-outline-danger me-2 ms-auto" (click)="delete()" [disabled]="!userIsOwner">
+    <button type="button" class="btn btn-sm btn-outline-danger me-2 ms-auto" (click)="delete()" [disabled]="!userIsOwner" *appIfPermissions="{ action: PermissionAction.Delete, type: PermissionType.Document }">
         <svg class="buttonicon" fill="currentColor">
             <use xlink:href="assets/bootstrap-icons.svg#trash" />
         </svg><span class="d-none d-lg-inline ps-1" i18n>Delete</span>
index 31e600b7da558c186276a21ed57ea8d030ff2478..d9e813c6a0262eba97e09460c153fcadedffc244 100644 (file)
@@ -496,7 +496,7 @@ export class DocumentDetailComponent
             this.toastService.showError(
               $localize`Error saving document` +
                 ': ' +
-                (error.message ?? error.toString())
+                (error.error?.detail ?? error.message ?? JSON.stringify(error))
             )
           }
         },
@@ -541,7 +541,7 @@ export class DocumentDetailComponent
           this.toastService.showError(
             $localize`Error saving document` +
               ': ' +
-              (error.message ?? error.toString())
+              (error.error?.detail ?? error.message ?? JSON.stringify(error))
           )
         },
       })
@@ -573,6 +573,10 @@ export class DocumentDetailComponent
     modal.componentInstance.message = $localize`The files for this document will be deleted permanently. This operation cannot be undone.`
     modal.componentInstance.btnClass = 'btn-danger'
     modal.componentInstance.btnCaption = $localize`Delete document`
+    this.subscribeModalDelete(modal) // so can be re-subscribed if error
+  }
+
+  subscribeModalDelete(modal) {
     modal.componentInstance.confirmClicked
       .pipe(
         switchMap(() => {
@@ -581,18 +585,21 @@ export class DocumentDetailComponent
         })
       )
       .pipe(takeUntil(this.unsubscribeNotifier))
-      .subscribe(
-        () => {
+      .subscribe({
+        next: () => {
           modal.close()
           this.close()
         },
-        (error) => {
+        error: (error) => {
           this.toastService.showError(
-            $localize`Error deleting document: ${JSON.stringify(error)}`
+            $localize`Error deleting document: ${
+              error.error?.detail ?? error.message ?? JSON.stringify(error)
+            }`
           )
           modal.componentInstance.buttonsEnabled = true
-        }
-      )
+          this.subscribeModalDelete(modal)
+        },
+      })
   }
 
   moreLike() {