Compare commits

..

24 Commits

Author SHA1 Message Date
shamoon
a0a9e0c6c8 Update views.py
[ci ckip]
2025-02-25 09:50:27 -08:00
shamoon
1c7c703e5f Merge migrations 2025-02-21 08:35:36 -08:00
shamoon
53e9e910d8 Merge branch 'dev' into feature-improve-paperless-task 2025-02-21 08:33:40 -08:00
shamoon
9fe611a24c Update views.py 2025-02-20 12:11:55 -08:00
shamoon
31e71aab83 Fix migrations merge 2025-02-17 08:19:11 -08:00
shamoon
7e7ce97d10 merge migrations 2025-02-17 08:19:11 -08:00
shamoon
e06adc58c7 Update tasks.service.ts 2025-02-17 08:19:11 -08:00
shamoon
7170ac31b7 Update test_api_tasks.py 2025-02-17 08:19:11 -08:00
shamoon
a0aa78c788 Translations 2025-02-17 08:19:11 -08:00
shamoon
f3438914cc Support acknowledged param 2025-02-17 08:19:11 -08:00
shamoon
e1b944ce6b Use choices for task name, rework task type 2025-02-17 08:19:11 -08:00
shamoon
0add5aab0e Styling, celery url 2025-02-17 08:19:11 -08:00
shamoon
c9adc74fa9 Styling, 4th column 2025-02-17 08:19:11 -08:00
shamoon
32abfbfc0a Health 2025-02-17 08:19:11 -08:00
shamoon
7f02f782f4 Fix warning 2025-02-17 08:19:11 -08:00
shamoon
7c3f011e84 Couple more test fixes 2025-02-17 08:19:11 -08:00
shamoon
5c68177960 Update tasks.py 2025-02-17 08:19:11 -08:00
shamoon
7a4666783e Fix tests, warning 2025-02-17 08:19:11 -08:00
shamoon
372825c271 Update translation strings 2025-02-17 08:19:11 -08:00
shamoon
abfddd6931 Fix tests 2025-02-17 08:19:11 -08:00
shamoon
b3d49dbf12 Add sanity check to system status 2025-02-17 08:19:11 -08:00
shamoon
673839265d Update system status to use classifier paperlesstask 2025-02-17 08:19:11 -08:00
shamoon
f31df22ab6 Revert "Tweak: more accurate classifier last trained time (#9004)"
This reverts commit 3314c59828.
2025-02-17 08:19:11 -08:00
shamoon
f897447a65 Create paperlesstasks for sanity, classifier
[ci skip]
2025-02-17 08:19:11 -08:00
63 changed files with 1101 additions and 1394 deletions

View File

@@ -123,13 +123,13 @@ RUN set -eux \
WORKDIR /usr/src/paperless/src/docker/ WORKDIR /usr/src/paperless/src/docker/
COPY [ \ COPY [ \
"docker/rootfs/etc/ImageMagick-6/paperless-policy.xml", \ "docker/imagemagick-policy.xml", \
"./" \ "./" \
] ]
RUN set -eux \ RUN set -eux \
&& echo "Configuring ImageMagick" \ && echo "Configuring ImageMagick" \
&& mv paperless-policy.xml /etc/ImageMagick-6/policy.xml && mv imagemagick-policy.xml /etc/ImageMagick-6/policy.xml
# Packages needed only for building a few quick Python # Packages needed only for building a few quick Python
# dependencies # dependencies

View File

@@ -65,7 +65,7 @@ services:
command: /bin/sh -c "chown -R paperless:paperless /usr/src/paperless/paperless-ngx/src/documents/static/frontend && chown -R paperless:paperless /usr/src/paperless/paperless-ngx/.ruff_cache && while sleep 1000; do :; done" command: /bin/sh -c "chown -R paperless:paperless /usr/src/paperless/paperless-ngx/src/documents/static/frontend && chown -R paperless:paperless /usr/src/paperless/paperless-ngx/.ruff_cache && while sleep 1000; do :; done"
gotenberg: gotenberg:
image: docker.io/gotenberg/gotenberg:8.17 image: docker.io/gotenberg/gotenberg:7.10
restart: unless-stopped restart: unless-stopped
# The Gotenberg Chromium route is used to convert .eml files. We do not # The Gotenberg Chromium route is used to convert .eml files. We do not

View File

@@ -5,7 +5,7 @@
services: services:
gotenberg: gotenberg:
image: docker.io/gotenberg/gotenberg:8.17 image: docker.io/gotenberg/gotenberg:8.7
hostname: gotenberg hostname: gotenberg
container_name: gotenberg container_name: gotenberg
network_mode: host network_mode: host

View File

@@ -77,7 +77,7 @@ services:
PAPERLESS_TIKA_ENDPOINT: http://tika:9998 PAPERLESS_TIKA_ENDPOINT: http://tika:9998
gotenberg: gotenberg:
image: docker.io/gotenberg/gotenberg:8.17 image: docker.io/gotenberg/gotenberg:8.7
restart: unless-stopped restart: unless-stopped
# The gotenberg chromium route is used to convert .eml files. We do not # The gotenberg chromium route is used to convert .eml files. We do not
# want to allow external content like tracking pixels or even javascript. # want to allow external content like tracking pixels or even javascript.

View File

@@ -71,7 +71,7 @@ services:
PAPERLESS_TIKA_ENDPOINT: http://tika:9998 PAPERLESS_TIKA_ENDPOINT: http://tika:9998
gotenberg: gotenberg:
image: docker.io/gotenberg/gotenberg:8.17 image: docker.io/gotenberg/gotenberg:8.7
restart: unless-stopped restart: unless-stopped
# The gotenberg chromium route is used to convert .eml files. We do not # The gotenberg chromium route is used to convert .eml files. We do not

View File

@@ -59,7 +59,7 @@ services:
PAPERLESS_TIKA_ENDPOINT: http://tika:9998 PAPERLESS_TIKA_ENDPOINT: http://tika:9998
gotenberg: gotenberg:
image: docker.io/gotenberg/gotenberg:8.17 image: docker.io/gotenberg/gotenberg:8.7
restart: unless-stopped restart: unless-stopped
# The gotenberg chromium route is used to convert .eml files. We do not # The gotenberg chromium route is used to convert .eml files. We do not

View File

@@ -1,18 +1,10 @@
#!/command/with-contenv /usr/bin/bash #!/command/with-contenv /usr/bin/bash
# shellcheck shell=bash # shellcheck shell=bash
cd ${PAPERLESS_SRC_DIR}
if [[ -n "${PAPERLESS_CONSUMER_DISABLE}" ]]; then if [[ -n "${USER_IS_NON_ROOT}" ]]; then
echo "[svc-consumer] Consumer is disabled, exiting"
# https://skarnet.org/software/s6/s6-svc.html
s6-svc -Od .
else
cd ${PAPERLESS_SRC_DIR}
if [[ -n "${USER_IS_NON_ROOT}" ]]; then
exec python3 manage.py document_consumer exec python3 manage.py document_consumer
else else
exec s6-setuidgid paperless python3 manage.py document_consumer exec s6-setuidgid paperless python3 manage.py document_consumer
fi
fi fi

View File

@@ -1030,11 +1030,6 @@ be used with caution!
## Document Consumption {#consume_config} ## Document Consumption {#consume_config}
#### [`PAPERLESS_CONSUMER_DISABLE=<bool>`](#PAPERLESS_CONSUMER_DISABLE) {#PAPERLESS_CONSUMER_DISABLE}
: Completely disable the directory-based consumer in docker. If you don't plan to consume documents
via the consumption directory, you can disable the consumer to save resources.
#### [`PAPERLESS_CONSUMER_DELETE_DUPLICATES=<bool>`](#PAPERLESS_CONSUMER_DELETE_DUPLICATES) {#PAPERLESS_CONSUMER_DELETE_DUPLICATES} #### [`PAPERLESS_CONSUMER_DELETE_DUPLICATES=<bool>`](#PAPERLESS_CONSUMER_DELETE_DUPLICATES) {#PAPERLESS_CONSUMER_DELETE_DUPLICATES}
: When the consumer detects a duplicate document, it will not touch : When the consumer detects a duplicate document, it will not touch

View File

@@ -714,8 +714,6 @@ the Pi and configuring some options in paperless can help improve
performance immensely: performance immensely:
- Stick with SQLite to save some resources. - Stick with SQLite to save some resources.
- If you do not need the filesystem-based consumer, consider disabling it
entirely by setting [`PAPERLESS_CONSUMER_DISABLE`](configuration.md#PAPERLESS_CONSUMER_DISABLE) to `true`.
- Consider setting [`PAPERLESS_OCR_PAGES`](configuration.md#PAPERLESS_OCR_PAGES) to 1, so that paperless will - Consider setting [`PAPERLESS_OCR_PAGES`](configuration.md#PAPERLESS_OCR_PAGES) to 1, so that paperless will
only OCR the first page of your documents. In most cases, this page only OCR the first page of your documents. In most cases, this page
contains enough information to be able to find it. contains enough information to be able to find it.

File diff suppressed because it is too large Load Diff

View File

@@ -303,12 +303,17 @@ describe('SettingsComponent', () => {
redis_error: redis_error:
'Error 61 connecting to localhost:6379. Connection refused.', 'Error 61 connecting to localhost:6379. Connection refused.',
celery_status: SystemStatusItemStatus.ERROR, celery_status: SystemStatusItemStatus.ERROR,
celery_url: 'celery@localhost',
celery_error: 'Error connecting to celery@localhost',
index_status: SystemStatusItemStatus.OK, index_status: SystemStatusItemStatus.OK,
index_last_modified: new Date().toISOString(), index_last_modified: new Date().toISOString(),
index_error: null, index_error: null,
classifier_status: SystemStatusItemStatus.OK, classifier_status: SystemStatusItemStatus.OK,
classifier_last_trained: new Date().toISOString(), classifier_last_trained: new Date().toISOString(),
classifier_error: null, classifier_error: null,
sanity_check_status: SystemStatusItemStatus.ERROR,
sanity_check_last_run: new Date().toISOString(),
sanity_check_error: 'Error running sanity check.',
}, },
} }
jest.spyOn(systemStatusService, 'get').mockReturnValue(of(status)) jest.spyOn(systemStatusService, 'get').mockReturnValue(of(status))

View File

@@ -19,6 +19,7 @@ import { allIcons, NgxBootstrapIconsModule } from 'ngx-bootstrap-icons'
import { routes } from 'src/app/app-routing.module' import { routes } from 'src/app/app-routing.module'
import { import {
PaperlessTask, PaperlessTask,
PaperlessTaskName,
PaperlessTaskStatus, PaperlessTaskStatus,
PaperlessTaskType, PaperlessTaskType,
} from 'src/app/data/paperless-task' } from 'src/app/data/paperless-task'
@@ -39,7 +40,8 @@ const tasks: PaperlessTask[] = [
task_file_name: 'test.pdf', task_file_name: 'test.pdf',
date_created: new Date('2023-03-01T10:26:03.093116Z'), date_created: new Date('2023-03-01T10:26:03.093116Z'),
date_done: new Date('2023-03-01T10:26:07.223048Z'), date_done: new Date('2023-03-01T10:26:07.223048Z'),
type: PaperlessTaskType.File, type: PaperlessTaskType.Auto,
task_name: PaperlessTaskName.ConsumeFile,
status: PaperlessTaskStatus.Failed, status: PaperlessTaskStatus.Failed,
result: 'test.pd: Not consuming test.pdf: It is a duplicate of test (#100)', result: 'test.pd: Not consuming test.pdf: It is a duplicate of test (#100)',
acknowledged: false, acknowledged: false,
@@ -51,7 +53,8 @@ const tasks: PaperlessTask[] = [
task_file_name: '191092.pdf', task_file_name: '191092.pdf',
date_created: new Date('2023-03-01T09:26:03.093116Z'), date_created: new Date('2023-03-01T09:26:03.093116Z'),
date_done: new Date('2023-03-01T09:26:07.223048Z'), date_done: new Date('2023-03-01T09:26:07.223048Z'),
type: PaperlessTaskType.File, type: PaperlessTaskType.Auto,
task_name: PaperlessTaskName.ConsumeFile,
status: PaperlessTaskStatus.Failed, status: PaperlessTaskStatus.Failed,
result: result:
'191092.pd: Not consuming 191092.pdf: It is a duplicate of 191092 (#311)', '191092.pd: Not consuming 191092.pdf: It is a duplicate of 191092 (#311)',
@@ -64,7 +67,8 @@ const tasks: PaperlessTask[] = [
task_file_name: 'Scan Jun 6, 2023 at 3.19 PM.pdf', task_file_name: 'Scan Jun 6, 2023 at 3.19 PM.pdf',
date_created: new Date('2023-06-06T15:22:05.722323-07:00'), date_created: new Date('2023-06-06T15:22:05.722323-07:00'),
date_done: new Date('2023-06-06T15:22:14.564305-07:00'), date_done: new Date('2023-06-06T15:22:14.564305-07:00'),
type: PaperlessTaskType.File, type: PaperlessTaskType.Auto,
task_name: PaperlessTaskName.ConsumeFile,
status: PaperlessTaskStatus.Pending, status: PaperlessTaskStatus.Pending,
result: null, result: null,
acknowledged: false, acknowledged: false,
@@ -76,7 +80,8 @@ const tasks: PaperlessTask[] = [
task_file_name: 'paperless-mail-l4dkg8ir', task_file_name: 'paperless-mail-l4dkg8ir',
date_created: new Date('2023-06-04T11:24:32.898089-07:00'), date_created: new Date('2023-06-04T11:24:32.898089-07:00'),
date_done: new Date('2023-06-04T11:24:44.678605-07:00'), date_done: new Date('2023-06-04T11:24:44.678605-07:00'),
type: PaperlessTaskType.File, type: PaperlessTaskType.Auto,
task_name: PaperlessTaskName.ConsumeFile,
status: PaperlessTaskStatus.Complete, status: PaperlessTaskStatus.Complete,
result: 'Success. New document id 422 created', result: 'Success. New document id 422 created',
acknowledged: false, acknowledged: false,
@@ -88,7 +93,8 @@ const tasks: PaperlessTask[] = [
task_file_name: 'onlinePaymentSummary.pdf', task_file_name: 'onlinePaymentSummary.pdf',
date_created: new Date('2023-06-01T13:49:51.631305-07:00'), date_created: new Date('2023-06-01T13:49:51.631305-07:00'),
date_done: new Date('2023-06-01T13:49:54.190220-07:00'), date_done: new Date('2023-06-01T13:49:54.190220-07:00'),
type: PaperlessTaskType.File, type: PaperlessTaskType.Auto,
task_name: PaperlessTaskName.ConsumeFile,
status: PaperlessTaskStatus.Complete, status: PaperlessTaskStatus.Complete,
result: 'Success. New document id 421 created', result: 'Success. New document id 421 created',
acknowledged: false, acknowledged: false,
@@ -100,7 +106,8 @@ const tasks: PaperlessTask[] = [
task_file_name: 'paperless-mail-_rrpmqk6', task_file_name: 'paperless-mail-_rrpmqk6',
date_created: new Date('2023-06-07T02:54:35.694916Z'), date_created: new Date('2023-06-07T02:54:35.694916Z'),
date_done: null, date_done: null,
type: PaperlessTaskType.File, type: PaperlessTaskType.Auto,
task_name: PaperlessTaskName.ConsumeFile,
status: PaperlessTaskStatus.Started, status: PaperlessTaskStatus.Started,
result: null, result: null,
acknowledged: false, acknowledged: false,
@@ -155,7 +162,9 @@ describe('TasksComponent', () => {
jest.useFakeTimers() jest.useFakeTimers()
fixture.detectChanges() fixture.detectChanges()
httpTestingController httpTestingController
.expectOne(`${environment.apiBaseUrl}tasks/`) .expectOne(
`${environment.apiBaseUrl}tasks/?task_name=consume_file&acknowledged=false`
)
.flush(tasks) .flush(tasks)
}) })

View File

@@ -84,7 +84,7 @@ export class SplitConfirmDialogComponent
addSplit() { addSplit() {
if (this.page === this.totalPages) return if (this.page === this.totalPages) return
this.pages.add(this.page) this.pages.add(this.page)
this.pages = new Set(Array.from(this.pages).sort((a, b) => a - b)) this.pages = new Set(Array.from(this.pages).sort())
this.confirmButtonEnabled = this.pages.size > 0 this.confirmButtonEnabled = this.pages.size > 0
} }

View File

@@ -9,24 +9,19 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-4">
<pngx-input-text [horizontal]="true" i18n-title title="Name" formControlName="name" [error]="error?.name" autocomplete="off"></pngx-input-text> <pngx-input-text [horizontal]="true" i18n-title title="Name" formControlName="name" [error]="error?.name" autocomplete="off"></pngx-input-text>
</div> </div>
<div class="col-md-4"> <div class="col-md-3">
<pngx-input-select [horizontal]="true" i18n-title title="Account" [items]="accounts" formControlName="account"></pngx-input-select> <pngx-input-select [horizontal]="true" i18n-title title="Account" [items]="accounts" formControlName="account"></pngx-input-select>
</div> </div>
<div class="col-md-3">
<pngx-input-number [horizontal]="true" i18n-title title="Order" formControlName="order" [showAdd]="false" [error]="error?.order"></pngx-input-number>
</div>
<div class="col-md-2 pt-2"> <div class="col-md-2 pt-2">
<pngx-input-switch [horizontal]="true" i18n-title title="Enabled" formControlName="enabled"></pngx-input-switch> <pngx-input-switch [horizontal]="true" i18n-title title="Enabled" formControlName="enabled"></pngx-input-switch>
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-6">
<pngx-input-number [horizontal]="true" i18n-title title="Order" formControlName="order" [showAdd]="false" [error]="error?.order"></pngx-input-number>
</div>
<div class="col-md-6">
<pngx-input-switch [horizontal]="true" i18n-title title="Stop further processing" formControlName="stop_processing" i18n-hint hint="Stop processing further rules if this rule queues any document(s)."></pngx-input-switch>
</div>
</div>
<hr class="mt-0"/> <hr class="mt-0"/>
<div class="row"> <div class="row">
<p class="small" i18n>Paperless will only process mails that match <em>all</em> of the criteria specified below.</p> <p class="small" i18n>Paperless will only process mails that match <em>all</em> of the criteria specified below.</p>

View File

@@ -221,7 +221,6 @@ export class MailRuleEditDialogComponent extends EditDialogComponent<MailRule> {
), ),
assign_correspondent: new FormControl(null), assign_correspondent: new FormControl(null),
assign_owner_from_rule: new FormControl(true), assign_owner_from_rule: new FormControl(true),
stop_processing: new FormControl(false),
}) })
} }

View File

@@ -1,32 +0,0 @@
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">{{title}}</h4>
<button type="button" class="btn-close" aria-label="Close" (click)="close()"></button>
</div>
<div class="modal-body">
<div class="mb-1">
<label for="email" class="form-label" i18n>Email address(es)</label>
<input type="email" class="form-control" id="email" [(ngModel)]="emailAddress">
</div>
<div class="mb-1">
<label for="email" class="form-label" i18n>Subject</label>
<input type="email" class="form-control" id="subject" [(ngModel)]="emailSubject">
</div>
<div>
<label for="message" class="form-label" i18n>Message</label>
<textarea class="form-control" id="message" rows="3" [(ngModel)]="emailMessage"></textarea>
</div>
</div>
<div class="modal-footer">
<div class="input-group">
<div class="input-group-text flex-grow-1">
<input class="form-check-input mt-0 me-2" type="checkbox" role="switch" id="useArchiveVersion" [disabled]="!hasArchiveVersion" [(ngModel)]="useArchiveVersion">
<label class="form-check-label w-100 text-start" for="useArchiveVersion" i18n>Use archive version</label>
</div>
<button type="submit" class="btn btn-outline-primary" (click)="emailDocument()" [disabled]="loading || emailAddress.length === 0 || emailMessage.length === 0 || emailSubject.length === 0">
@if (loading) {
<div class="spinner-border spinner-border-sm me-2" role="status"></div>
}
<ng-container i18n>Send email</ng-container>
</button>
</div>
</div>

View File

@@ -1,72 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
import { provideHttpClientTesting } from '@angular/common/http/testing'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
import { of, throwError } from 'rxjs'
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
import { PermissionsService } from 'src/app/services/permissions.service'
import { DocumentService } from 'src/app/services/rest/document.service'
import { ToastService } from 'src/app/services/toast.service'
import { EmailDocumentDialogComponent } from './email-document-dialog.component'
describe('EmailDocumentDialogComponent', () => {
let component: EmailDocumentDialogComponent
let fixture: ComponentFixture<EmailDocumentDialogComponent>
let documentService: DocumentService
let permissionsService: PermissionsService
let toastService: ToastService
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
EmailDocumentDialogComponent,
IfPermissionsDirective,
NgxBootstrapIconsModule.pick(allIcons),
],
providers: [
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
NgbActiveModal,
],
}).compileComponents()
fixture = TestBed.createComponent(EmailDocumentDialogComponent)
documentService = TestBed.inject(DocumentService)
toastService = TestBed.inject(ToastService)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should set hasArchiveVersion and useArchiveVersion', () => {
expect(component.hasArchiveVersion).toBeTruthy()
component.hasArchiveVersion = false
expect(component.hasArchiveVersion).toBeFalsy()
expect(component.useArchiveVersion).toBeFalsy()
})
it('should support sending document via email, showing error if needed', () => {
const toastErrorSpy = jest.spyOn(toastService, 'showError')
const toastSuccessSpy = jest.spyOn(toastService, 'showInfo')
component.emailAddress = 'hello@paperless-ngx.com'
component.emailSubject = 'Hello'
component.emailMessage = 'World'
jest
.spyOn(documentService, 'emailDocument')
.mockReturnValue(throwError(() => new Error('Unable to email document')))
component.emailDocument()
expect(toastErrorSpy).toHaveBeenCalled()
jest.spyOn(documentService, 'emailDocument').mockReturnValue(of(true))
component.emailDocument()
expect(toastSuccessSpy).toHaveBeenCalled()
})
it('should close the dialog', () => {
const activeModal = TestBed.inject(NgbActiveModal)
const closeSpy = jest.spyOn(activeModal, 'close')
component.close()
expect(closeSpy).toHaveBeenCalled()
})
})

View File

@@ -1,77 +0,0 @@
import { Component, Input } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons'
import { DocumentService } from 'src/app/services/rest/document.service'
import { ToastService } from 'src/app/services/toast.service'
import { LoadingComponentWithPermissions } from '../../loading-component/loading.component'
@Component({
selector: 'pngx-email-document-dialog',
templateUrl: './email-document-dialog.component.html',
styleUrl: './email-document-dialog.component.scss',
imports: [FormsModule, NgxBootstrapIconsModule],
})
export class EmailDocumentDialogComponent extends LoadingComponentWithPermissions {
@Input()
title = $localize`Email Document`
@Input()
documentId: number
private _hasArchiveVersion: boolean = true
@Input()
set hasArchiveVersion(value: boolean) {
this._hasArchiveVersion = value
this.useArchiveVersion = value
}
get hasArchiveVersion(): boolean {
return this._hasArchiveVersion
}
public useArchiveVersion: boolean = true
public emailAddress: string = ''
public emailSubject: string = ''
public emailMessage: string = ''
constructor(
private activeModal: NgbActiveModal,
private documentService: DocumentService,
private toastService: ToastService
) {
super()
this.loading = false
}
public emailDocument() {
this.loading = true
this.documentService
.emailDocument(
this.documentId,
this.emailAddress,
this.emailSubject,
this.emailMessage,
this.useArchiveVersion
)
.subscribe({
next: () => {
this.loading = false
this.emailAddress = ''
this.emailSubject = ''
this.emailMessage = ''
this.toastService.showInfo($localize`Email sent`)
},
error: (e) => {
this.loading = false
this.toastService.showError($localize`Error emailing document`, e)
},
})
}
public close() {
this.activeModal.close()
}
}

View File

@@ -1,68 +0,0 @@
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">{{title}}</h4>
<button type="button" class="btn-close" aria-label="Close" (click)="close()"></button>
</div>
<div class="modal-body p-0">
<ul class="list-group list-group-flush">
@if (!shareLinks || shareLinks.length === 0) {
<li class="list-group-item fst-italic small text-center text-secondary" i18n>
No existing links
</li>
}
@for (link of shareLinks; track link) {
<li class="list-group-item">
<div class="input-group w-100">
<input type="text" class="form-control" aria-label="Share link" [value]="getShareUrl(link)" readonly>
@if (link.expiration) {
<span class="input-group-text">
{{ getDaysRemaining(link) }}
</span>
}
<button type="button" class="btn btn-outline-primary" (click)="copy(link)">
@if (copied !== link.id) {
<i-bs width="1.2em" height="1.2em" name="clipboard-fill"></i-bs>
}
@if (copied === link.id) {
<i-bs width="1.2em" height="1.2em" name="clipboard-check-fill"></i-bs>
}
<span class="visually-hidden" i18n>Copy</span>
</button>
@if (canShare(link)) {
<button type="button" class="btn btn-outline-primary" (click)="share(link)">
<i-bs width="1.2em" height="1.2em" name="box-arrow-up"></i-bs><span class="visually-hidden" i18n>Share</span>
</button>
}
<button type="button" class="btn btn-outline-danger" (click)="delete(link)">
<i-bs width="1.2em" height="1.2em" name="trash"></i-bs><span class="visually-hidden" i18n>Delete</span>
</button>
</div>
<span class="badge copied-badge bg-primary small fade ms-4 position-absolute top-50 translate-middle-y pe-none z-3" [class.show]="copied === link.id" i18n>Copied!</span>
</li>
}
</ul>
</div>
<div class="modal-footer">
<div class="input-group w-100">
<div class="form-check form-switch ms-auto">
<input class="form-check-input" type="checkbox" role="switch" id="versionSwitch" [disabled]="!hasArchiveVersion" [(ngModel)]="useArchiveVersion">
<label class="form-check-label" for="versionSwitch" i18n>Share archive version</label>
</div>
</div>
<div class="input-group w-100 mt-2">
<label class="input-group-text" for="addLink"><ng-container i18n>Expires</ng-container>:</label>
<select class="form-select fs-6" [(ngModel)]="expirationDays">
@for (option of EXPIRATION_OPTIONS; track option) {
<option [ngValue]="option.value">{{ option.label }}</option>
}
</select>
<button class="btn btn-outline-primary ms-auto" type="button" (click)="createLink()" [disabled]="loading">
@if (loading) {
<div class="spinner-border spinner-border-sm me-2" role="status"></div>
}
@if (!loading) {
<i-bs name="plus"></i-bs>
}
<ng-container i18n>Create</ng-container>
</button>
</div>
</div>

View File

@@ -1,3 +0,0 @@
.copied-badge {
right: 15em;
}

View File

@@ -0,0 +1,70 @@
<div ngbDropdown>
<button class="btn btn-sm btn-outline-primary" id="shareLinksDropdown" [disabled]="disabled" ngbDropdownToggle>
<i-bs name="link"></i-bs>
<div class="d-none d-sm-inline">&nbsp;<ng-container i18n>Share Links</ng-container></div>
</button>
<div ngbDropdownMenu aria-labelledby="shareLinksDropdown" class="shadow share-links-dropdown">
<ul class="list-group list-group-flush">
@if (!shareLinks || shareLinks.length === 0) {
<li class="list-group-item fst-italic small text-center text-secondary" i18n>
No existing links
</li>
}
@for (link of shareLinks; track link) {
<li class="list-group-item">
<div class="input-group input-group-sm w-100">
<input type="text" class="form-control" aria-label="Share link" [value]="getShareUrl(link)" readonly>
@if (link.expiration) {
<span class="input-group-text">
{{ getDaysRemaining(link) }}
</span>
}
<button type="button" class="btn btn-sm btn-outline-primary" (click)="copy(link)">
@if (copied !== link.id) {
<i-bs width="1.2em" height="1.2em" name="clipboard-fill"></i-bs>
}
@if (copied === link.id) {
<i-bs width="1.2em" height="1.2em" name="clipboard-check-fill"></i-bs>
}
<span class="visually-hidden" i18n>Copy</span>
</button>
@if (canShare(link)) {
<button type="button" class="btn btn-sm btn-outline-primary" (click)="share(link)">
<i-bs width="1.2em" height="1.2em" name="box-arrow-up"></i-bs><span class="visually-hidden" i18n>Share</span>
</button>
}
<button type="button" class="btn btn-sm btn-outline-danger" (click)="delete(link)">
<i-bs width="1.2em" height="1.2em" name="trash"></i-bs><span class="visually-hidden" i18n>Delete</span>
</button>
</div>
<span class="badge copied-badge bg-primary small fade ms-4 position-absolute top-50 translate-middle-y pe-none z-3" [class.show]="copied === link.id" i18n>Copied!</span>
</li>
}
<li class="list-group-item pt-3 pb-2">
<div class="input-group input-group-sm w-100">
<div class="form-check form-switch ms-auto small">
<input class="form-check-input" type="checkbox" role="switch" id="versionSwitch" [disabled]="!hasArchiveVersion" [(ngModel)]="useArchiveVersion">
<label class="form-check-label" for="versionSwitch" i18n>Share archive version</label>
</div>
</div>
<div class="input-group input-group-sm w-100 mt-2">
<label class="input-group-text" for="addLink"><ng-container i18n>Expires</ng-container>:</label>
<select class="form-select form-select-sm" [(ngModel)]="expirationDays">
@for (option of EXPIRATION_OPTIONS; track option) {
<option [ngValue]="option.value">{{ option.label }}</option>
}
</select>
<button class="btn btn-sm btn-outline-primary ms-auto" type="button" (click)="createLink()" [disabled]="loading">
@if (loading) {
<div class="spinner-border spinner-border-sm me-2" role="status"></div>
}
@if (!loading) {
<i-bs name="plus"></i-bs>
}
<ng-container i18n>Create</ng-container>
</button>
</div>
</li>
</ul>
</div>
</div>

View File

@@ -0,0 +1,14 @@
.share-links-dropdown {
min-width: 350px;
// correct position on mobile
@media (max-width: 575.98px) {
&.show {
margin-left: -175px !important;
}
}
}
.copied-badge {
right: 7.5em;
}

View File

@@ -11,18 +11,17 @@ import {
tick, tick,
} from '@angular/core/testing' } from '@angular/core/testing'
import { By } from '@angular/platform-browser' import { By } from '@angular/platform-browser'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons' import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
import { of, throwError } from 'rxjs' import { of, throwError } from 'rxjs'
import { FileVersion, ShareLink } from 'src/app/data/share-link' import { FileVersion, ShareLink } from 'src/app/data/share-link'
import { ShareLinkService } from 'src/app/services/rest/share-link.service' import { ShareLinkService } from 'src/app/services/rest/share-link.service'
import { ToastService } from 'src/app/services/toast.service' import { ToastService } from 'src/app/services/toast.service'
import { environment } from 'src/environments/environment' import { environment } from 'src/environments/environment'
import { ShareLinksDialogComponent } from './share-links-dialog.component' import { ShareLinksDropdownComponent } from './share-links-dropdown.component'
describe('ShareLinksDialogComponent', () => { describe('ShareLinksDropdownComponent', () => {
let component: ShareLinksDialogComponent let component: ShareLinksDropdownComponent
let fixture: ComponentFixture<ShareLinksDialogComponent> let fixture: ComponentFixture<ShareLinksDropdownComponent>
let shareLinkService: ShareLinkService let shareLinkService: ShareLinkService
let toastService: ToastService let toastService: ToastService
let httpController: HttpTestingController let httpController: HttpTestingController
@@ -31,17 +30,16 @@ describe('ShareLinksDialogComponent', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
ShareLinksDialogComponent, ShareLinksDropdownComponent,
NgxBootstrapIconsModule.pick(allIcons), NgxBootstrapIconsModule.pick(allIcons),
], ],
providers: [ providers: [
provideHttpClient(withInterceptorsFromDi()), provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(), provideHttpClientTesting(),
NgbActiveModal,
], ],
}) })
fixture = TestBed.createComponent(ShareLinksDialogComponent) fixture = TestBed.createComponent(ShareLinksDropdownComponent)
shareLinkService = TestBed.inject(ShareLinkService) shareLinkService = TestBed.inject(ShareLinkService)
toastService = TestBed.inject(ToastService) toastService = TestBed.inject(ToastService)
httpController = TestBed.inject(HttpTestingController) httpController = TestBed.inject(HttpTestingController)
@@ -234,11 +232,4 @@ describe('ShareLinksDialogComponent', () => {
] ]
).toBeTruthy() ).toBeTruthy()
}) })
it('should support close', () => {
const activeModal = TestBed.inject(NgbActiveModal)
const closeSpy = jest.spyOn(activeModal, 'close')
component.close()
expect(closeSpy).toHaveBeenCalled()
})
}) })

View File

@@ -1,7 +1,7 @@
import { Clipboard } from '@angular/cdk/clipboard' import { Clipboard } from '@angular/cdk/clipboard'
import { Component, Input, OnInit } from '@angular/core' import { Component, Input, OnInit } from '@angular/core'
import { FormsModule, ReactiveFormsModule } from '@angular/forms' import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'
import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons' import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons'
import { first } from 'rxjs' import { first } from 'rxjs'
import { FileVersion, ShareLink } from 'src/app/data/share-link' import { FileVersion, ShareLink } from 'src/app/data/share-link'
@@ -10,12 +10,17 @@ import { ToastService } from 'src/app/services/toast.service'
import { environment } from 'src/environments/environment' import { environment } from 'src/environments/environment'
@Component({ @Component({
selector: 'pngx-share-links-dialog', selector: 'pngx-share-links-dropdown',
templateUrl: './share-links-dialog.component.html', templateUrl: './share-links-dropdown.component.html',
styleUrls: ['./share-links-dialog.component.scss'], styleUrls: ['./share-links-dropdown.component.scss'],
imports: [FormsModule, ReactiveFormsModule, NgxBootstrapIconsModule], imports: [
FormsModule,
ReactiveFormsModule,
NgbDropdownModule,
NgxBootstrapIconsModule,
],
}) })
export class ShareLinksDialogComponent implements OnInit { export class ShareLinksDropdownComponent implements OnInit {
EXPIRATION_OPTIONS = [ EXPIRATION_OPTIONS = [
{ label: $localize`1 day`, value: 1 }, { label: $localize`1 day`, value: 1 },
{ label: $localize`7 days`, value: 7 }, { label: $localize`7 days`, value: 7 },
@@ -36,6 +41,9 @@ export class ShareLinksDialogComponent implements OnInit {
} }
} }
@Input()
disabled: boolean = false
private _hasArchiveVersion: boolean = true private _hasArchiveVersion: boolean = true
@Input() @Input()
@@ -59,7 +67,6 @@ export class ShareLinksDialogComponent implements OnInit {
useArchiveVersion: boolean = true useArchiveVersion: boolean = true
constructor( constructor(
private activeModal: NgbActiveModal,
private shareLinkService: ShareLinkService, private shareLinkService: ShareLinkService,
private toastService: ToastService, private toastService: ToastService,
private clipboard: Clipboard private clipboard: Clipboard
@@ -162,8 +169,4 @@ export class ShareLinksDialogComponent implements OnInit {
}, },
}) })
} }
close() {
this.activeModal.close()
}
} }

View File

@@ -1,5 +1,5 @@
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="modal-basic-title" i18n>System Status</h5> <h6 class="modal-title" id="modal-basic-title" i18n>System Status</h6>
<button type="button" class="btn-close" aria-label="Close" (click)="close()"></button> <button type="button" class="btn-close" aria-label="Close" (click)="close()"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
@@ -11,11 +11,11 @@
</div> </div>
</div> </div>
} @else { } @else {
<div class="row row-cols-1 row-cols-md-3 g-3"> <div class="row row-cols-1 row-cols-md-4 g-3">
<div class="col"> <div class="col-4">
<div class="card bg-light h-100"> <div class="card bg-light h-100">
<div class="card-header"> <div class="card-header">
<h5 class="card-title mb-0" i18n>Environment</h5> <h6 class="card-title mb-0" i18n>Environment</h6>
</div> </div>
<div class="card-body"> <div class="card-body">
<dl class="card-text"> <dl class="card-text">
@@ -38,27 +38,37 @@
<div class="col"> <div class="col">
<div class="card bg-light h-100"> <div class="card bg-light h-100">
<div class="card-header"> <div class="card-header">
<h5 class="card-title mb-0" i18n>Database</h5> <h6 class="card-title mb-0" i18n>Database</h6>
</div> </div>
<div class="card-body"> <div class="card-body">
<dl class="card-text"> <dl class="card-text">
<dt i18n>Type</dt> <dt i18n>Type</dt>
<dd>{{status.database.type}}</dd> <dd>{{status.database.type}}</dd>
<dt i18n>Status</dt> <dt i18n>Status</dt>
<dd class="d-flex align-items-center"> <dd>
<div class="badge text-uppercase bg-info text-dark" [ngbPopover]="databaseStatus" triggers="mouseenter:mouseleave">
{{status.database.status}} {{status.database.status}}
@if (status.database.status === 'OK') { @if (status.database.status === 'OK') {
<i-bs name="check-circle-fill" class="text-primary ms-2 lh-1" ngbPopover="{{status.database.url}}" triggers="mouseenter:mouseleave"></i-bs> <i-bs name="check-circle-fill" class="text-primary ms-2 lh-1"></i-bs>
} @else { } @else {
<i-bs name="exclamation-triangle-fill" class="text-danger ms-2 lh-1" ngbPopover="{{status.database.url}}: {{status.database.error}}" triggers="mouseenter:mouseleave"></i-bs> <i-bs name="exclamation-triangle-fill" class="text-danger ms-2 lh-1"></i-bs>
} }
</div>
<ng-template #databaseStatus>
@if (status.database.status === 'OK') {
{{status.database.url}}
} @else {
{{status.database.url}}: {{status.database.error}}
}
</ng-template>
</dd> </dd>
<dt i18n>Migration Status</dt> <dt i18n>Migration Status</dt>
<dd class="d-flex align-items-center"> <dd>
<div class="badge text-uppercase bg-info text-dark" [ngbPopover]="migrationStatus" triggers="mouseenter:mouseleave">
@if (status.database.migration_status.unapplied_migrations.length === 0) { @if (status.database.migration_status.unapplied_migrations.length === 0) {
<ng-container i18n>Up to date</ng-container><i-bs name="check-circle-fill" class="text-primary ms-2 lh-1" [ngbPopover]="migrationStatus" triggers="mouseenter:mouseleave"></i-bs> <ng-container i18n>Up to date</ng-container><i-bs name="check-circle-fill" class="text-primary ms-2 lh-1"></i-bs>
} @else { } @else {
<ng-container>{{status.database.migration_status.unapplied_migrations.length}} Pending</ng-container><i-bs name="exclamation-triangle-fill" class="text-warning ms-2 lh-1" [ngbPopover]="migrationStatus" triggers="mouseenter:mouseleave"></i-bs> <ng-container>{{status.database.migration_status.unapplied_migrations.length}} Pending</ng-container><i-bs name="exclamation-triangle-fill" class="text-warning ms-2 lh-1"></i-bs>
} }
<ng-template #migrationStatus> <ng-template #migrationStatus>
<h6><ng-container i18n>Latest Migration</ng-container>:</h6> <span class="font-monospace small">{{status.database.migration_status.latest_migration}}</span> <h6><ng-container i18n>Latest Migration</ng-container>:</h6> <span class="font-monospace small">{{status.database.migration_status.latest_migration}}</span>
@@ -71,6 +81,7 @@
</ul> </ul>
} }
</ng-template> </ng-template>
</div>
</dd> </dd>
</dl> </dl>
</div> </div>
@@ -80,63 +91,127 @@
<div class="col"> <div class="col">
<div class="card bg-light h-100"> <div class="card bg-light h-100">
<div class="card-header"> <div class="card-header">
<h5 class="card-title mb-0" i18n>Tasks</h5> <h6 class="card-title mb-0" i18n>Tasks Queue</h6>
</div> </div>
<div class="card-body"> <div class="card-body">
<dl class="card-text"> <dl class="card-text">
<dt i18n>Redis Status</dt> <dt i18n>Redis Status</dt>
<dd class="d-flex align-items-center"> <dd>
<div class="badge text-uppercase bg-info text-dark" [ngbPopover]="redisStatus" triggers="mouseenter:mouseleave">
{{status.tasks.redis_status}} {{status.tasks.redis_status}}
@if (status.tasks.redis_status === 'OK') { @if (status.tasks.redis_status === 'OK') {
<i-bs name="check-circle-fill" class="text-primary ms-2 lh-1" ngbPopover="{{status.tasks.redis_url}}" triggers="mouseenter:mouseleave"></i-bs> <i-bs name="check-circle-fill" class="text-primary ms-2 lh-1"></i-bs>
} @else { } @else {
<i-bs name="exclamation-triangle-fill" class="text-danger ms-2 lh-1" ngbPopover="{{status.tasks.redis_url}}: {{status.tasks.redis_error}}" triggers="mouseenter:mouseleave"></i-bs> <i-bs name="exclamation-triangle-fill" class="text-danger ms-2 lh-1"></i-bs>
} }
</div>
<ng-template #redisStatus>
@if (status.tasks.redis_status === 'OK') {
{{status.tasks.redis_url}}
} @else {
{{status.tasks.redis_url}}: {{status.tasks.redis_error}}
}
</ng-template>
</dd> </dd>
<dt i18n>Celery Status</dt> <dt i18n>Celery Status</dt>
<dd class="d-flex align-items-center"> <dd>
<div class="badge text-uppercase bg-info text-dark" [ngbPopover]="celeryStatus" triggers="mouseenter:mouseleave">
{{status.tasks.celery_status}} {{status.tasks.celery_status}}
@if (status.tasks.celery_status === 'OK') { @if (status.tasks.celery_status === 'OK') {
<i-bs name="check-circle-fill" class="text-primary ms-2 lh-1"></i-bs> <i-bs name="check-circle-fill" class="text-primary ms-2 lh-1"></i-bs>
} @else { } @else {
<i-bs name="exclamation-triangle-fill" class="text-danger ms-2 lh-1"></i-bs> <i-bs name="exclamation-triangle-fill" class="text-danger ms-2 lh-1"></i-bs>
} }
</div>
<ng-template #celeryStatus>
@if (status.tasks.celery_status === 'OK') {
{{status.tasks.celery_url}}
} @else {
{{status.tasks.celery_error}}
}
</ng-template>
</dd> </dd>
</dl>
</div>
</div>
</div>
<div class="col">
<div class="card bg-light h-100">
<div class="card-header">
<h6 class="card-title mb-0" i18n>Health</h6>
</div>
<div class="card-body">
<dl class="card-text">
<dt i18n>Search Index</dt> <dt i18n>Search Index</dt>
<dd class="d-flex align-items-center"> <dd>
<div class="badge text-uppercase bg-info text-dark" [ngbPopover]="indexStatus" triggers="mouseenter:mouseleave">
{{status.tasks.index_status}} {{status.tasks.index_status}}
@if (status.tasks.index_status === 'OK') { @if (status.tasks.index_status === 'OK') {
@if (isStale(status.tasks.index_last_modified)) { @if (isStale(status.tasks.index_last_modified)) {
<i-bs name="exclamation-triangle-fill" class="text-warning ms-2 lh-1" [ngbPopover]="indexStatus" triggers="mouseenter:mouseleave"></i-bs> <i-bs name="exclamation-triangle-fill" class="text-warning ms-2 lh-1"></i-bs>
} @else { } @else {
<i-bs name="check-circle-fill" class="text-primary ms-2 lh-1" [ngbPopover]="indexStatus" triggers="mouseenter:mouseleave"></i-bs> <i-bs name="check-circle-fill" class="text-primary ms-2 lh-1"></i-bs>
} }
} @else { } @else {
<i-bs name="exclamation-triangle-fill" class="text-danger ms-2 lh-1" ngbPopover="{{status.tasks.index_error}}" triggers="mouseenter:mouseleave"></i-bs> <i-bs name="exclamation-triangle-fill" class="text-danger ms-2 lh-1"></i-bs>
} }
</div>
</dd> </dd>
<ng-template #indexStatus> <ng-template #indexStatus>
@if (status.tasks.index_status === 'OK') {
<h6><ng-container i18n>Last Updated</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.index_last_modified | customDate:'medium'}}</span> <h6><ng-container i18n>Last Updated</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.index_last_modified | customDate:'medium'}}</span>
} @else {
<h6><ng-container i18n>Error</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.index_error}}</span>
}
</ng-template> </ng-template>
<dt i18n>Classifier</dt> <dt i18n>Classifier</dt>
<dd class="d-flex align-items-center"> <dd>
<div class="badge text-uppercase bg-info text-dark" [ngbPopover]="classifierStatus" triggers="mouseenter:mouseleave">
{{status.tasks.classifier_status}} {{status.tasks.classifier_status}}
@if (status.tasks.classifier_status === 'OK') { @if (status.tasks.classifier_status === 'OK') {
@if (isStale(status.tasks.classifier_last_trained)) { @if (isStale(status.tasks.classifier_last_trained)) {
<i-bs name="exclamation-triangle-fill" class="text-warning ms-2 lh-1" [ngbPopover]="classifierStatus" triggers="mouseenter:mouseleave"></i-bs> <i-bs name="exclamation-triangle-fill" class="text-warning ms-2 lh-1"></i-bs>
} @else { } @else {
<i-bs name="check-circle-fill" class="text-primary ms-2 lh-1" [ngbPopover]="classifierStatus" triggers="mouseenter:mouseleave"></i-bs> <i-bs name="check-circle-fill" class="text-primary ms-2 lh-1"></i-bs>
} }
} @else { } @else {
<i-bs name="exclamation-triangle-fill" class="ms-2 lh-1" <i-bs name="exclamation-triangle-fill" class="ms-2 lh-1"
[class.text-danger]="status.tasks.classifier_status === SystemStatusItemStatus.ERROR" [class.text-danger]="status.tasks.classifier_status === SystemStatusItemStatus.ERROR"
[class.text-warning]="status.tasks.classifier_status === SystemStatusItemStatus.WARNING" [class.text-warning]="status.tasks.classifier_status === SystemStatusItemStatus.WARNING"></i-bs>
ngbPopover="{{status.tasks.classifier_error}}"
triggers="mouseenter:mouseleave"></i-bs>
} }
</div>
</dd> </dd>
<ng-template #classifierStatus> <ng-template #classifierStatus>
@if (status.tasks.classifier_status === 'OK') {
<h6><ng-container i18n>Last Trained</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.classifier_last_trained | customDate:'medium'}}</span> <h6><ng-container i18n>Last Trained</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.classifier_last_trained | customDate:'medium'}}</span>
} @else {
<h6><ng-container i18n>Error</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.classifier_error}}</span>
}
</ng-template>
<dt i18n>Sanity Checker</dt>
<dd>
<div class="badge text-uppercase bg-info text-dark" [ngbPopover]="sanityCheckerStatus" triggers="mouseenter:mouseleave">
{{status.tasks.sanity_check_status}}
@if (status.tasks.sanity_check_status === 'OK') {
@if (isStale(status.tasks.sanity_check_last_run)) {
<i-bs name="exclamation-triangle-fill" class="text-warning ms-2 lh-1"></i-bs>
} @else {
<i-bs name="check-circle-fill" class="text-primary ms-2 lh-1"></i-bs>
}
} @else {
<i-bs name="exclamation-triangle-fill" class="ms-2 lh-1"
[class.text-danger]="status.tasks.sanity_check_status === SystemStatusItemStatus.ERROR"
[class.text-warning]="status.tasks.sanity_check_status === SystemStatusItemStatus.WARNING"></i-bs>
}
</div>
</dd>
<ng-template #sanityCheckerStatus>
@if (status.tasks.sanity_check_status === 'OK') {
<h6><ng-container i18n>Last Run</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.sanity_check_last_run | customDate:'medium'}}</span>
} @else {
<h6><ng-container i18n>Error</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.sanity_check_error}}</span>
}
</ng-template> </ng-template>
</dl> </dl>
</div> </div>

View File

@@ -0,0 +1,3 @@
.border-primary {
--bs-border-color: var(--bs-primary);
}

View File

@@ -36,12 +36,17 @@ const status: SystemStatus = {
redis_status: SystemStatusItemStatus.ERROR, redis_status: SystemStatusItemStatus.ERROR,
redis_error: 'Error 61 connecting to localhost:6379. Connection refused.', redis_error: 'Error 61 connecting to localhost:6379. Connection refused.',
celery_status: SystemStatusItemStatus.ERROR, celery_status: SystemStatusItemStatus.ERROR,
celery_url: 'celery@localhost',
celery_error: 'Error connecting to celery@localhost',
index_status: SystemStatusItemStatus.OK, index_status: SystemStatusItemStatus.OK,
index_last_modified: new Date().toISOString(), index_last_modified: new Date().toISOString(),
index_error: null, index_error: null,
classifier_status: SystemStatusItemStatus.OK, classifier_status: SystemStatusItemStatus.OK,
classifier_last_trained: new Date().toISOString(), classifier_last_trained: new Date().toISOString(),
classifier_error: null, classifier_error: null,
sanity_check_status: SystemStatusItemStatus.OK,
sanity_check_last_run: new Date().toISOString(),
sanity_check_error: null,
}, },
} }

View File

@@ -81,24 +81,7 @@
(added)="addField($event)"> (added)="addField($event)">
</pngx-custom-fields-dropdown> </pngx-custom-fields-dropdown>
<pngx-share-links-dropdown [documentId]="documentId" [hasArchiveVersion]="!!document?.archived_file_name" [disabled]="!userCanEdit && !userIsOwner" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.ShareLink }"></pngx-share-links-dropdown>
<div class="ms-auto" ngbDropdown>
<button class="btn btn-sm btn-outline-primary" id="sendDropdown" ngbDropdownToggle>
<i-bs name="send"></i-bs>
<div class="d-none d-sm-inline">&nbsp;<ng-container i18n>Send</ng-container></div>
</button>
<div ngbDropdownMenu aria-labelledby="actionsDropdown" class="shadow">
<button ngbDropdownItem (click)="openShareLinks()" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.ShareLink }">
<i-bs name="link"></i-bs>&nbsp;<span i18n>Share Links</span>
</button>
@if (emailEnabled) {
<button ngbDropdownItem (click)="openEmailDocument()">
<i-bs name="envelope"></i-bs>&nbsp;<span i18n>Email</span>
</button>
}
</div>
</div>
</pngx-page-header> </pngx-page-header>
<div class="row"> <div class="row">

View File

@@ -1330,18 +1330,4 @@ describe('DocumentDetailComponent', () => {
expect(createSpy).toHaveBeenCalledWith('a') expect(createSpy).toHaveBeenCalledWith('a')
expect(urlRevokeSpy).toHaveBeenCalled() expect(urlRevokeSpy).toHaveBeenCalled()
}) })
it('should get email enabled status from settings', () => {
jest.spyOn(settingsService, 'get').mockReturnValue(true)
expect(component.emailEnabled).toBeTruthy()
})
it('should support open share links and email modals', () => {
const modalSpy = jest.spyOn(modalService, 'open')
initNormally()
component.openShareLinks()
expect(modalSpy).toHaveBeenCalled()
component.openEmailDocument()
expect(modalSpy).toHaveBeenCalled()
})
}) })

View File

@@ -88,7 +88,6 @@ import { CorrespondentEditDialogComponent } from '../common/edit-dialog/correspo
import { DocumentTypeEditDialogComponent } from '../common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component' import { DocumentTypeEditDialogComponent } from '../common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component'
import { EditDialogMode } from '../common/edit-dialog/edit-dialog.component' import { EditDialogMode } from '../common/edit-dialog/edit-dialog.component'
import { StoragePathEditDialogComponent } from '../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component' import { StoragePathEditDialogComponent } from '../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component'
import { EmailDocumentDialogComponent } from '../common/email-document-dialog/email-document-dialog.component'
import { CheckComponent } from '../common/input/check/check.component' import { CheckComponent } from '../common/input/check/check.component'
import { DateComponent } from '../common/input/date/date.component' import { DateComponent } from '../common/input/date/date.component'
import { DocumentLinkComponent } from '../common/input/document-link/document-link.component' import { DocumentLinkComponent } from '../common/input/document-link/document-link.component'
@@ -100,7 +99,7 @@ import { TagsComponent } from '../common/input/tags/tags.component'
import { TextComponent } from '../common/input/text/text.component' import { TextComponent } from '../common/input/text/text.component'
import { UrlComponent } from '../common/input/url/url.component' import { UrlComponent } from '../common/input/url/url.component'
import { PageHeaderComponent } from '../common/page-header/page-header.component' import { PageHeaderComponent } from '../common/page-header/page-header.component'
import { ShareLinksDialogComponent } from '../common/share-links-dialog/share-links-dialog.component' import { ShareLinksDropdownComponent } from '../common/share-links-dropdown/share-links-dropdown.component'
import { DocumentHistoryComponent } from '../document-history/document-history.component' import { DocumentHistoryComponent } from '../document-history/document-history.component'
import { DocumentNotesComponent } from '../document-notes/document-notes.component' import { DocumentNotesComponent } from '../document-notes/document-notes.component'
import { ComponentWithPermissions } from '../with-permissions/with-permissions.component' import { ComponentWithPermissions } from '../with-permissions/with-permissions.component'
@@ -146,6 +145,7 @@ export enum ZoomSetting {
CustomFieldsDropdownComponent, CustomFieldsDropdownComponent,
DocumentNotesComponent, DocumentNotesComponent,
DocumentHistoryComponent, DocumentHistoryComponent,
ShareLinksDropdownComponent,
CheckComponent, CheckComponent,
DateComponent, DateComponent,
DocumentLinkComponent, DocumentLinkComponent,
@@ -1426,26 +1426,6 @@ export class DocumentDetailComponent
}) })
} }
public openShareLinks() {
const modal = this.modalService.open(ShareLinksDialogComponent)
modal.componentInstance.documentId = this.document.id
modal.componentInstance.hasArchiveVersion =
!!this.document?.archived_file_name
}
get emailEnabled(): boolean {
return this.settings.get(SETTINGS_KEYS.EMAIL_ENABLED)
}
public openEmailDocument() {
const modal = this.modalService.open(EmailDocumentDialogComponent, {
backdrop: 'static',
})
modal.componentInstance.documentId = this.document.id
modal.componentInstance.hasArchiveVersion =
!!this.document?.archived_file_name
}
private tryRenderTiff() { private tryRenderTiff() {
this.http.get(this.previewUrl, { responseType: 'arraybuffer' }).subscribe({ this.http.get(this.previewUrl, { responseType: 'arraybuffer' }).subscribe({
next: (res) => { next: (res) => {

View File

@@ -84,6 +84,4 @@ export interface MailRule extends ObjectWithPermissions {
assign_correspondent?: number // PaperlessCorrespondent.id assign_correspondent?: number // PaperlessCorrespondent.id
assign_owner_from_rule: boolean assign_owner_from_rule: boolean
stop_processing: boolean
} }

View File

@@ -1,8 +1,15 @@
import { ObjectWithId } from './object-with-id' import { ObjectWithId } from './object-with-id'
export enum PaperlessTaskType { export enum PaperlessTaskType {
// just file tasks, for now Auto = 'auto_task',
File = 'file', ScheduledTask = 'scheduled_task',
ManualTask = 'manual_task',
}
export enum PaperlessTaskName {
ConsumeFile = 'consume_file',
TrainClassifier = 'train_classifier',
SanityCheck = 'check_sanity',
} }
export enum PaperlessTaskStatus { export enum PaperlessTaskStatus {
@@ -23,6 +30,8 @@ export interface PaperlessTask extends ObjectWithId {
task_file_name: string task_file_name: string
task_name: PaperlessTaskName
date_created: Date date_created: Date
date_done?: Date date_done?: Date

View File

@@ -32,11 +32,16 @@ export interface SystemStatus {
redis_status: SystemStatusItemStatus redis_status: SystemStatusItemStatus
redis_error: string redis_error: string
celery_status: SystemStatusItemStatus celery_status: SystemStatusItemStatus
celery_url: string
celery_error: string
index_status: SystemStatusItemStatus index_status: SystemStatusItemStatus
index_last_modified: string // ISO date string index_last_modified: string // ISO date string
index_error: string index_error: string
classifier_status: SystemStatusItemStatus classifier_status: SystemStatusItemStatus
classifier_last_trained: string // ISO date string classifier_last_trained: string // ISO date string
classifier_error: string classifier_error: string
sanity_check_status: SystemStatusItemStatus
sanity_check_last_run: string // ISO date string
sanity_check_error: string
} }
} }

View File

@@ -355,21 +355,6 @@ it('should include custom fields in sort fields if user has permission', () => {
]) ])
}) })
it('should call appropriate api endpoint for email document', () => {
subscription = service
.emailDocument(
documents[0].id,
'hello@paperless-ngx.com',
'hello',
'world',
true
)
.subscribe()
httpTestingController.expectOne(
`${environment.apiBaseUrl}${endpoint}/${documents[0].id}/email/`
)
})
afterEach(() => { afterEach(() => {
subscription?.unsubscribe() subscription?.unsubscribe()
httpTestingController.verify() httpTestingController.verify()

View File

@@ -258,19 +258,4 @@ export class DocumentService extends AbstractPaperlessService<Document> {
public get searchQuery(): string { public get searchQuery(): string {
return this._searchQuery return this._searchQuery
} }
emailDocument(
documentId: number,
addresses: string,
subject: string,
message: string,
useArchiveVersion: boolean
): Observable<any> {
return this.http.post(this.getResourceUrl(documentId, 'email'), {
addresses: addresses,
subject: subject,
message: message,
use_archive_version: useArchiveVersion,
})
}
} }

View File

@@ -33,7 +33,6 @@ const mail_rules = [
action: MailAction.MarkRead, action: MailAction.MarkRead,
assign_title_from: MailMetadataTitleOption.FromSubject, assign_title_from: MailMetadataTitleOption.FromSubject,
assign_owner_from_rule: true, assign_owner_from_rule: true,
stop_processing: false,
}, },
{ {
name: 'Mail Rule 2', name: 'Mail Rule 2',
@@ -53,7 +52,6 @@ const mail_rules = [
action: MailAction.Delete, action: MailAction.Delete,
assign_title_from: MailMetadataTitleOption.FromSubject, assign_title_from: MailMetadataTitleOption.FromSubject,
assign_owner_from_rule: true, assign_owner_from_rule: true,
stop_processing: false,
}, },
{ {
name: 'Mail Rule 3', name: 'Mail Rule 3',
@@ -73,7 +71,6 @@ const mail_rules = [
action: MailAction.Flag, action: MailAction.Flag,
assign_title_from: MailMetadataTitleOption.FromSubject, assign_title_from: MailMetadataTitleOption.FromSubject,
assign_owner_from_rule: false, assign_owner_from_rule: false,
stop_processing: false,
}, },
] ]

View File

@@ -5,7 +5,11 @@ import {
} from '@angular/common/http/testing' } from '@angular/common/http/testing'
import { TestBed } from '@angular/core/testing' import { TestBed } from '@angular/core/testing'
import { environment } from 'src/environments/environment' import { environment } from 'src/environments/environment'
import { PaperlessTaskStatus, PaperlessTaskType } from '../data/paperless-task' import {
PaperlessTaskName,
PaperlessTaskStatus,
PaperlessTaskType,
} from '../data/paperless-task'
import { TasksService } from './tasks.service' import { TasksService } from './tasks.service'
describe('TasksService', () => { describe('TasksService', () => {
@@ -33,7 +37,7 @@ describe('TasksService', () => {
it('calls tasks api endpoint on reload', () => { it('calls tasks api endpoint on reload', () => {
tasksService.reload() tasksService.reload()
const req = httpTestingController.expectOne( const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}tasks/` `${environment.apiBaseUrl}tasks/?task_name=consume_file&acknowledged=false`
) )
expect(req.request.method).toEqual('GET') expect(req.request.method).toEqual('GET')
}) })
@@ -41,7 +45,9 @@ describe('TasksService', () => {
it('does not call tasks api endpoint on reload if already loading', () => { it('does not call tasks api endpoint on reload if already loading', () => {
tasksService.loading = true tasksService.loading = true
tasksService.reload() tasksService.reload()
httpTestingController.expectNone(`${environment.apiBaseUrl}tasks/`) httpTestingController.expectNone(
`${environment.apiBaseUrl}tasks/?task_name=consume_file&acknowledged=false`
)
}) })
it('calls acknowledge_tasks api endpoint on dismiss and reloads', () => { it('calls acknowledge_tasks api endpoint on dismiss and reloads', () => {
@@ -55,14 +61,19 @@ describe('TasksService', () => {
}) })
req.flush([]) req.flush([])
// reload is then called // reload is then called
httpTestingController.expectOne(`${environment.apiBaseUrl}tasks/`).flush([]) httpTestingController
.expectOne(
`${environment.apiBaseUrl}tasks/?task_name=consume_file&acknowledged=false`
)
.flush([])
}) })
it('sorts tasks returned from api', () => { it('sorts tasks returned from api', () => {
expect(tasksService.total).toEqual(0) expect(tasksService.total).toEqual(0)
const mockTasks = [ const mockTasks = [
{ {
type: PaperlessTaskType.File, type: PaperlessTaskType.Auto,
task_name: PaperlessTaskName.ConsumeFile,
status: PaperlessTaskStatus.Complete, status: PaperlessTaskStatus.Complete,
acknowledged: false, acknowledged: false,
task_id: '1234', task_id: '1234',
@@ -70,7 +81,8 @@ describe('TasksService', () => {
date_created: new Date(), date_created: new Date(),
}, },
{ {
type: PaperlessTaskType.File, type: PaperlessTaskType.Auto,
task_name: PaperlessTaskName.ConsumeFile,
status: PaperlessTaskStatus.Failed, status: PaperlessTaskStatus.Failed,
acknowledged: false, acknowledged: false,
task_id: '1235', task_id: '1235',
@@ -78,7 +90,8 @@ describe('TasksService', () => {
date_created: new Date(), date_created: new Date(),
}, },
{ {
type: PaperlessTaskType.File, type: PaperlessTaskType.Auto,
task_name: PaperlessTaskName.ConsumeFile,
status: PaperlessTaskStatus.Pending, status: PaperlessTaskStatus.Pending,
acknowledged: false, acknowledged: false,
task_id: '1236', task_id: '1236',
@@ -86,7 +99,8 @@ describe('TasksService', () => {
date_created: new Date(), date_created: new Date(),
}, },
{ {
type: PaperlessTaskType.File, type: PaperlessTaskType.Auto,
task_name: PaperlessTaskName.ConsumeFile,
status: PaperlessTaskStatus.Started, status: PaperlessTaskStatus.Started,
acknowledged: false, acknowledged: false,
task_id: '1237', task_id: '1237',
@@ -94,7 +108,8 @@ describe('TasksService', () => {
date_created: new Date(), date_created: new Date(),
}, },
{ {
type: PaperlessTaskType.File, type: PaperlessTaskType.Auto,
task_name: PaperlessTaskName.ConsumeFile,
status: PaperlessTaskStatus.Complete, status: PaperlessTaskStatus.Complete,
acknowledged: false, acknowledged: false,
task_id: '1238', task_id: '1238',
@@ -106,7 +121,7 @@ describe('TasksService', () => {
tasksService.reload() tasksService.reload()
const req = httpTestingController.expectOne( const req = httpTestingController.expectOne(
`${environment.apiBaseUrl}tasks/` `${environment.apiBaseUrl}tasks/?task_name=consume_file&acknowledged=false`
) )
req.flush(mockTasks) req.flush(mockTasks)

View File

@@ -4,8 +4,8 @@ import { Subject } from 'rxjs'
import { first, takeUntil } from 'rxjs/operators' import { first, takeUntil } from 'rxjs/operators'
import { import {
PaperlessTask, PaperlessTask,
PaperlessTaskName,
PaperlessTaskStatus, PaperlessTaskStatus,
PaperlessTaskType,
} from 'src/app/data/paperless-task' } from 'src/app/data/paperless-task'
import { environment } from 'src/environments/environment' import { environment } from 'src/environments/environment'
@@ -54,10 +54,14 @@ export class TasksService {
this.loading = true this.loading = true
this.http this.http
.get<PaperlessTask[]>(`${this.baseUrl}tasks/`) .get<PaperlessTask[]>(
`${this.baseUrl}tasks/?task_name=consume_file&acknowledged=false`
)
.pipe(takeUntil(this.unsubscribeNotifer), first()) .pipe(takeUntil(this.unsubscribeNotifer), first())
.subscribe((r) => { .subscribe((r) => {
this.fileTasks = r.filter((t) => t.type == PaperlessTaskType.File) // they're all File tasks, for now this.fileTasks = r.filter(
(t) => t.task_name == PaperlessTaskName.ConsumeFile
)
this.loading = false this.loading = false
}) })
} }

View File

@@ -112,7 +112,6 @@ import {
questionCircle, questionCircle,
scissors, scissors,
search, search,
send,
slashCircle, slashCircle,
sliders2Vertical, sliders2Vertical,
sortAlphaDown, sortAlphaDown,
@@ -317,7 +316,6 @@ const icons = {
questionCircle, questionCircle,
scissors, scissors,
search, search,
send,
slashCircle, slashCircle,
sliders2Vertical, sliders2Vertical,
sortAlphaDown, sortAlphaDown,

View File

@@ -21,10 +21,12 @@
--pngx-success-darken-10: hsl(152, 69%, 11%); // based on success #198754 --pngx-success-darken-10: hsl(152, 69%, 11%); // based on success #198754
--pngx-bg-alt: #fff; --pngx-bg-alt: #fff;
--pngx-bg-darker: var(--bs-gray-100); --pngx-bg-darker: var(--bs-gray-100);
--pngx-bg-alt2: var(--bs-gray-200); --pngx-bg-alt2: var(--bs-gray-200); // #e9ecef
--pngx-bg-disabled: #f7f7f7; --pngx-bg-disabled: #f7f7f7;
--pngx-focus-alpha: 0.3; --pngx-focus-alpha: 0.3;
--pngx-toast-max-width: 360px; --pngx-toast-max-width: 360px;
--bs-info: var(--pngx-bg-alt2);
--bs-info-rgb: 233, 236, 239;
@media screen and (min-width: 1024px) { @media screen and (min-width: 1024px) {
--pngx-toast-max-width: 450px; --pngx-toast-max-width: 450px;
} }
@@ -71,8 +73,15 @@ $form-check-radio-checked-bg-image-dark: url("data:image/svg+xml,<svg xmlns='htt
} }
@mixin dark-mode { @mixin dark-mode {
--bs-body-color: #{$text-color-dark-bg};
--pngx-body-color-accent: #{$text-color-dark-bg-accent}; --pngx-body-color-accent: #{$text-color-dark-bg-accent};
--pngx-bg-alt: #242529;
--pngx-bg-alt2: #232323;
--pngx-bg-darker: #101216;
--pngx-bg-disabled: var(--pngx-bg-alt);
--pngx-focus-alpha: 0.6;
--pngx-primary-faded: var(--pngx-primary-darken-15);
--pngx-primary-text-contrast: var(--bs-body-color);
--bs-body-color: #{$text-color-dark-bg};
--bs-secondary-color: #6c757d; --bs-secondary-color: #6c757d;
--bs-danger: #b71631; --bs-danger: #b71631;
--bs-danger-rgb: 183, 22, 49; --bs-danger-rgb: 183, 22, 49;
@@ -80,15 +89,10 @@ $form-check-radio-checked-bg-image-dark: url("data:image/svg+xml,<svg xmlns='htt
--bs-body-bg-rgb: 22, 22, 24; --bs-body-bg-rgb: 22, 22, 24;
--bs-light: #1c1c1f; --bs-light: #1c1c1f;
--bs-light-rgb: 28, 28, 31; --bs-light-rgb: 28, 28, 31;
--bs-info: var(--pngx-bg-alt);
--bs-info-rgb: 36, 36, 39;
--bs-border-color: #47494f; --bs-border-color: #47494f;
--pngx-bg-alt2: #232323;
--pngx-bg-darker: #101216;
--bs-tertiary-bg: var(--pngx-bg-darker); --bs-tertiary-bg: var(--pngx-bg-darker);
--pngx-bg-alt: #242529;
--pngx-bg-disabled: var(--pngx-bg-alt);
--pngx-focus-alpha: 0.6;
--pngx-primary-faded: var(--pngx-primary-darken-15);
--pngx-primary-text-contrast: var(--bs-body-color);
--bs-dark-border-subtle: var(--pngx-bg-darker); --bs-dark-border-subtle: var(--pngx-bg-darker);
--bs-border-color-translucent: rgba(0, 0, 0, .175); // override bs --bs-border-color-translucent: rgba(0, 0, 0, .175); // override bs

View File

@@ -1,7 +1,6 @@
import logging import logging
import pickle import pickle
import re import re
import time
import warnings import warnings
from collections.abc import Iterator from collections.abc import Iterator
from hashlib import sha256 from hashlib import sha256
@@ -142,19 +141,6 @@ class DocumentClassifier:
): ):
raise IncompatibleClassifierVersionError("sklearn version update") raise IncompatibleClassifierVersionError("sklearn version update")
def set_last_checked(self) -> None:
# save a timestamp of the last time we checked for retraining to a file
with Path(settings.MODEL_FILE.with_suffix(".last_checked")).open("w") as f:
f.write(str(time.time()))
def get_last_checked(self) -> float | None:
# load the timestamp of the last time we checked for retraining
try:
with Path(settings.MODEL_FILE.with_suffix(".last_checked")).open("r") as f:
return float(f.read())
except FileNotFoundError: # pragma: no cover
return None
def save(self) -> None: def save(self) -> None:
target_file: Path = settings.MODEL_FILE target_file: Path = settings.MODEL_FILE
target_file_temp: Path = target_file.with_suffix(".pickle.part") target_file_temp: Path = target_file.with_suffix(".pickle.part")
@@ -175,7 +161,6 @@ class DocumentClassifier:
pickle.dump(self.storage_path_classifier, f) pickle.dump(self.storage_path_classifier, f)
target_file_temp.rename(target_file) target_file_temp.rename(target_file)
self.set_last_checked()
def train(self) -> bool: def train(self) -> bool:
# Get non-inbox documents # Get non-inbox documents
@@ -244,7 +229,6 @@ class DocumentClassifier:
and self.last_doc_change_time >= latest_doc_change and self.last_doc_change_time >= latest_doc_change
) and self.last_auto_type_hash == hasher.digest(): ) and self.last_auto_type_hash == hasher.digest():
logger.info("No updates since last training") logger.info("No updates since last training")
self.set_last_checked()
# Set the classifier information into the cache # Set the classifier information into the cache
# Caching for 50 minutes, so slightly less than the normal retrain time # Caching for 50 minutes, so slightly less than the normal retrain time
cache.set( cache.set(

View File

@@ -35,6 +35,7 @@ from documents.models import CustomFieldInstance
from documents.models import Document from documents.models import Document
from documents.models import DocumentType from documents.models import DocumentType
from documents.models import Log from documents.models import Log
from documents.models import PaperlessTask
from documents.models import ShareLink from documents.models import ShareLink
from documents.models import StoragePath from documents.models import StoragePath
from documents.models import Tag from documents.models import Tag
@@ -770,6 +771,21 @@ class ShareLinkFilterSet(FilterSet):
} }
class PaperlessTaskFilterSet(FilterSet):
acknowledged = BooleanFilter(
label="Acknowledged",
field_name="acknowledged",
)
class Meta:
model = PaperlessTask
fields = {
"type": ["exact"],
"task_name": ["exact"],
"status": ["exact"],
}
class ObjectOwnedOrGrantedPermissionsFilter(ObjectPermissionsFilter): class ObjectOwnedOrGrantedPermissionsFilter(ObjectPermissionsFilter):
""" """
A filter backend that limits results to those where the requesting user A filter backend that limits results to those where the requesting user

View File

@@ -10,4 +10,4 @@ class Command(BaseCommand):
) )
def handle(self, *args, **options): def handle(self, *args, **options):
train_classifier() train_classifier(scheduled=False)

View File

@@ -12,6 +12,6 @@ class Command(ProgressBarMixin, BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
self.handle_progress_bar_mixin(**options) self.handle_progress_bar_mixin(**options)
messages = check_sanity(progress=self.use_progress_bar) messages = check_sanity(progress=self.use_progress_bar, scheduled=False)
messages.log_messages() messages.log_messages()

View File

@@ -1,4 +1,4 @@
# Generated by Django 5.1.6 on 2025-02-20 04:55 # Generated by Django 5.1.6 on 2025-02-21 16:34
import multiselectfield.db.fields import multiselectfield.db.fields
from django.db import migrations from django.db import migrations
@@ -16,12 +16,51 @@ def update_workflow_sources(apps, schema_editor):
trigger.save() trigger.save()
def make_existing_tasks_consume_auto(apps, schema_editor):
PaperlessTask = apps.get_model("documents", "PaperlessTask")
PaperlessTask.objects.all().update(type="auto_task", task_name="consume_file")
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
("documents", "1062_alter_savedviewfilterrule_rule_type"), ("documents", "1062_alter_savedviewfilterrule_rule_type"),
] ]
operations = [ operations = [
migrations.AddField(
model_name="paperlesstask",
name="type",
field=models.CharField(
choices=[
("auto_task", "Auto Task"),
("scheduled_task", "Scheduled Task"),
("manual_task", "Manual Task"),
],
default="auto_task",
help_text="The type of task that was run",
max_length=30,
verbose_name="Task Type",
),
),
migrations.AlterField(
model_name="paperlesstask",
name="task_name",
field=models.CharField(
choices=[
("consume_file", "Consume File"),
("train_classifier", "Train Classifier"),
("check_sanity", "Check Sanity"),
],
help_text="Name of the task that was run",
max_length=255,
null=True,
verbose_name="Task Name",
),
),
migrations.RunPython(
code=make_existing_tasks_consume_auto,
reverse_code=migrations.RunPython.noop,
),
migrations.AlterField( migrations.AlterField(
model_name="workflowactionwebhook", model_name="workflowactionwebhook",
name="url", name="url",

View File

@@ -650,6 +650,16 @@ class PaperlessTask(ModelWithOwner):
ALL_STATES = sorted(states.ALL_STATES) ALL_STATES = sorted(states.ALL_STATES)
TASK_STATE_CHOICES = sorted(zip(ALL_STATES, ALL_STATES)) TASK_STATE_CHOICES = sorted(zip(ALL_STATES, ALL_STATES))
class TaskType(models.TextChoices):
AUTO = ("auto_task", _("Auto Task"))
SCHEDULED_TASK = ("scheduled_task", _("Scheduled Task"))
MANUAL_TASK = ("manual_task", _("Manual Task"))
class TaskName(models.TextChoices):
CONSUME_FILE = ("consume_file", _("Consume File"))
TRAIN_CLASSIFIER = ("train_classifier", _("Train Classifier"))
CHECK_SANITY = ("check_sanity", _("Check Sanity"))
task_id = models.CharField( task_id = models.CharField(
max_length=255, max_length=255,
unique=True, unique=True,
@@ -673,8 +683,9 @@ class PaperlessTask(ModelWithOwner):
task_name = models.CharField( task_name = models.CharField(
null=True, null=True,
max_length=255, max_length=255,
choices=TaskName.choices,
verbose_name=_("Task Name"), verbose_name=_("Task Name"),
help_text=_("Name of the Task which was run"), help_text=_("Name of the task that was run"),
) )
status = models.CharField( status = models.CharField(
@@ -684,24 +695,28 @@ class PaperlessTask(ModelWithOwner):
verbose_name=_("Task State"), verbose_name=_("Task State"),
help_text=_("Current state of the task being run"), help_text=_("Current state of the task being run"),
) )
date_created = models.DateTimeField( date_created = models.DateTimeField(
null=True, null=True,
default=timezone.now, default=timezone.now,
verbose_name=_("Created DateTime"), verbose_name=_("Created DateTime"),
help_text=_("Datetime field when the task result was created in UTC"), help_text=_("Datetime field when the task result was created in UTC"),
) )
date_started = models.DateTimeField( date_started = models.DateTimeField(
null=True, null=True,
default=None, default=None,
verbose_name=_("Started DateTime"), verbose_name=_("Started DateTime"),
help_text=_("Datetime field when the task was started in UTC"), help_text=_("Datetime field when the task was started in UTC"),
) )
date_done = models.DateTimeField( date_done = models.DateTimeField(
null=True, null=True,
default=None, default=None,
verbose_name=_("Completed DateTime"), verbose_name=_("Completed DateTime"),
help_text=_("Datetime field when the task was completed in UTC"), help_text=_("Datetime field when the task was completed in UTC"),
) )
result = models.TextField( result = models.TextField(
null=True, null=True,
default=None, default=None,
@@ -711,6 +726,14 @@ class PaperlessTask(ModelWithOwner):
), ),
) )
type = models.CharField(
max_length=30,
choices=TaskType.choices,
default=TaskType.AUTO,
verbose_name=_("Task Type"),
help_text=_("The type of task that was run"),
)
def __str__(self) -> str: def __str__(self) -> str:
return f"Task {self.task_id}" return f"Task {self.task_id}"

View File

@@ -1,13 +1,17 @@
import hashlib import hashlib
import logging import logging
import uuid
from collections import defaultdict from collections import defaultdict
from pathlib import Path from pathlib import Path
from typing import Final from typing import Final
from celery import states
from django.conf import settings from django.conf import settings
from django.utils import timezone
from tqdm import tqdm from tqdm import tqdm
from documents.models import Document from documents.models import Document
from documents.models import PaperlessTask
class SanityCheckMessages: class SanityCheckMessages:
@@ -57,7 +61,17 @@ class SanityCheckFailedException(Exception):
pass pass
def check_sanity(*, progress=False) -> SanityCheckMessages: def check_sanity(*, progress=False, scheduled=True) -> SanityCheckMessages:
paperless_task = PaperlessTask.objects.create(
task_id=uuid.uuid4(),
type=PaperlessTask.TaskType.SCHEDULED_TASK
if scheduled
else PaperlessTask.TaskType.MANUAL_TASK,
task_name=PaperlessTask.TaskName.CHECK_SANITY,
status=states.STARTED,
date_created=timezone.now(),
date_started=timezone.now(),
)
messages = SanityCheckMessages() messages = SanityCheckMessages()
present_files = { present_files = {
@@ -142,4 +156,11 @@ def check_sanity(*, progress=False) -> SanityCheckMessages:
for extra_file in present_files: for extra_file in present_files:
messages.warning(None, f"Orphaned file in media dir: {extra_file}") messages.warning(None, f"Orphaned file in media dir: {extra_file}")
paperless_task.status = states.SUCCESS if not messages.has_error else states.FAILURE
# result is concatenated messages
paperless_task.result = f"{len(messages)} issues found."
if messages.has_error:
paperless_task.result += " Check logs for details."
paperless_task.date_done = timezone.now()
paperless_task.save(update_fields=["status", "result", "date_done"])
return messages return messages

View File

@@ -1704,6 +1704,7 @@ class TasksViewSerializer(OwnedObjectSerializer):
fields = ( fields = (
"id", "id",
"task_id", "task_id",
"task_name",
"task_file_name", "task_file_name",
"date_created", "date_created",
"date_done", "date_done",
@@ -1715,12 +1716,6 @@ class TasksViewSerializer(OwnedObjectSerializer):
"owner", "owner",
) )
type = serializers.SerializerMethodField()
def get_type(self, obj) -> str:
# just file tasks, for now
return "file"
related_document = serializers.SerializerMethodField() related_document = serializers.SerializerMethodField()
created_doc_re = re.compile(r"New document id (\d+) created") created_doc_re = re.compile(r"New document id (\d+) created")
duplicate_doc_re = re.compile(r"It is a duplicate of .* \(#(\d+)\)") duplicate_doc_re = re.compile(r"It is a duplicate of .* \(#(\d+)\)")
@@ -1728,6 +1723,7 @@ class TasksViewSerializer(OwnedObjectSerializer):
def get_related_document(self, obj) -> str | None: def get_related_document(self, obj) -> str | None:
result = None result = None
re = None re = None
if obj.result:
match obj.status: match obj.status:
case states.SUCCESS: case states.SUCCESS:
re = self.created_doc_re re = self.created_doc_re

View File

@@ -1221,10 +1221,11 @@ def before_task_publish_handler(sender=None, headers=None, body=None, **kwargs):
user_id = overrides.owner_id if overrides else None user_id = overrides.owner_id if overrides else None
PaperlessTask.objects.create( PaperlessTask.objects.create(
type=PaperlessTask.TaskType.AUTO,
task_id=headers["id"], task_id=headers["id"],
status=states.PENDING, status=states.PENDING,
task_file_name=task_file_name, task_file_name=task_file_name,
task_name=headers["task"], task_name=PaperlessTask.TaskName.CONSUME_FILE,
result=None, result=None,
date_created=timezone.now(), date_created=timezone.now(),
date_started=None, date_started=None,

View File

@@ -9,6 +9,7 @@ from tempfile import TemporaryDirectory
import tqdm import tqdm
from celery import Task from celery import Task
from celery import shared_task from celery import shared_task
from celery import states
from django.conf import settings from django.conf import settings
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import models from django.db import models
@@ -35,6 +36,7 @@ from documents.models import Correspondent
from documents.models import CustomFieldInstance from documents.models import CustomFieldInstance
from documents.models import Document from documents.models import Document
from documents.models import DocumentType from documents.models import DocumentType
from documents.models import PaperlessTask
from documents.models import StoragePath from documents.models import StoragePath
from documents.models import Tag from documents.models import Tag
from documents.models import Workflow from documents.models import Workflow
@@ -74,19 +76,34 @@ def index_reindex(*, progress_bar_disable=False):
@shared_task @shared_task
def train_classifier(): def train_classifier(*, scheduled=True):
task = PaperlessTask.objects.create(
type=PaperlessTask.TaskType.SCHEDULED_TASK
if scheduled
else PaperlessTask.TaskType.MANUAL_TASK,
task_id=uuid.uuid4(),
task_name=PaperlessTask.TaskName.TRAIN_CLASSIFIER,
status=states.STARTED,
date_created=timezone.now(),
date_started=timezone.now(),
)
if ( if (
not Tag.objects.filter(matching_algorithm=Tag.MATCH_AUTO).exists() not Tag.objects.filter(matching_algorithm=Tag.MATCH_AUTO).exists()
and not DocumentType.objects.filter(matching_algorithm=Tag.MATCH_AUTO).exists() and not DocumentType.objects.filter(matching_algorithm=Tag.MATCH_AUTO).exists()
and not Correspondent.objects.filter(matching_algorithm=Tag.MATCH_AUTO).exists() and not Correspondent.objects.filter(matching_algorithm=Tag.MATCH_AUTO).exists()
and not StoragePath.objects.filter(matching_algorithm=Tag.MATCH_AUTO).exists() and not StoragePath.objects.filter(matching_algorithm=Tag.MATCH_AUTO).exists()
): ):
logger.info("No automatic matching items, not training") result = "No automatic matching items, not training"
logger.info(result)
# Special case, items were once auto and trained, so remove the model # Special case, items were once auto and trained, so remove the model
# and prevent its use again # and prevent its use again
if settings.MODEL_FILE.exists(): if settings.MODEL_FILE.exists():
logger.info(f"Removing {settings.MODEL_FILE} so it won't be used") logger.info(f"Removing {settings.MODEL_FILE} so it won't be used")
settings.MODEL_FILE.unlink() settings.MODEL_FILE.unlink()
task.status = states.SUCCESS
task.result = result
task.date_done = timezone.now()
task.save()
return return
classifier = load_classifier() classifier = load_classifier()
@@ -100,11 +117,19 @@ def train_classifier():
f"Saving updated classifier model to {settings.MODEL_FILE}...", f"Saving updated classifier model to {settings.MODEL_FILE}...",
) )
classifier.save() classifier.save()
task.result = "Training completed successfully"
else: else:
logger.debug("Training data unchanged.") logger.debug("Training data unchanged.")
task.result = "Training data unchanged"
task.status = states.SUCCESS
task.date_done = timezone.now()
task.save(update_fields=["status", "result", "date_done"])
except Exception as e: except Exception as e:
logger.warning("Classifier error: " + str(e)) logger.warning("Classifier error: " + str(e))
task.status = states.FAILURE
task.result = str(e)
@shared_task(bind=True) @shared_task(bind=True)

View File

@@ -15,7 +15,6 @@ from dateutil import parser
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core import mail
from django.core.cache import cache from django.core.cache import cache
from django.db import DataError from django.db import DataError
from django.test import override_settings from django.test import override_settings
@@ -2652,153 +2651,6 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
self.assertEqual(resp.status_code, status.HTTP_200_OK) self.assertEqual(resp.status_code, status.HTTP_200_OK)
self.assertEqual(doc1.tags.count(), 2) self.assertEqual(doc1.tags.count(), 2)
@override_settings(
EMAIL_ENABLED=True,
EMAIL_BACKEND="django.core.mail.backends.locmem.EmailBackend",
)
def test_email_document(self):
"""
GIVEN:
- Existing document
WHEN:
- API request is made to email document action
THEN:
- Email is sent, with document (original or archive) attached
"""
doc = Document.objects.create(
title="test",
mime_type="application/pdf",
content="this is a document 1",
checksum="1",
filename="test.pdf",
archive_checksum="A",
archive_filename="archive.pdf",
)
doc2 = Document.objects.create(
title="test2",
mime_type="application/pdf",
content="this is a document 2",
checksum="2",
filename="test2.pdf",
)
archive_file = Path(__file__).parent / "samples" / "simple.pdf"
source_file = Path(__file__).parent / "samples" / "simple.pdf"
shutil.copy(archive_file, doc.archive_path)
shutil.copy(source_file, doc2.source_path)
self.client.post(
f"/api/documents/{doc.pk}/email/",
{
"addresses": "hello@paperless-ngx.com",
"subject": "test",
"message": "hello",
},
)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].attachments[0][0], "archive.pdf")
self.client.post(
f"/api/documents/{doc2.pk}/email/",
{
"addresses": "hello@paperless-ngx.com",
"subject": "test",
"message": "hello",
"use_archive_version": False,
},
)
self.assertEqual(len(mail.outbox), 2)
self.assertEqual(mail.outbox[1].attachments[0][0], "test2.pdf")
@mock.patch("django.core.mail.message.EmailMessage.send", side_effect=Exception)
def test_email_document_errors(self, mocked_send):
"""
GIVEN:
- Existing document
WHEN:
- API request is made to email document action with insufficient permissions
- API request is made to email document action with invalid document id
- API request is made to email document action with missing data
- API request is made to email document action with invalid email address
- API request is made to email document action and error occurs during email send
THEN:
- Error response is returned
"""
user1 = User.objects.create_user(username="test1")
user1.user_permissions.add(*Permission.objects.all())
user1.save()
doc = Document.objects.create(
title="test",
mime_type="application/pdf",
content="this is a document 1",
checksum="1",
filename="test.pdf",
archive_checksum="A",
archive_filename="archive.pdf",
)
doc2 = Document.objects.create(
title="test2",
mime_type="application/pdf",
content="this is a document 2",
checksum="2",
owner=self.user,
)
self.client.force_authenticate(user1)
resp = self.client.post(
f"/api/documents/{doc2.pk}/email/",
{
"addresses": "hello@paperless-ngx.com",
"subject": "test",
"message": "hello",
},
)
self.assertEqual(resp.status_code, status.HTTP_403_FORBIDDEN)
resp = self.client.post(
"/api/documents/999/email/",
{
"addresses": "hello@paperless-ngx.com",
"subject": "test",
"message": "hello",
},
)
self.assertEqual(resp.status_code, status.HTTP_404_NOT_FOUND)
resp = self.client.post(
f"/api/documents/{doc.pk}/email/",
{
"addresses": "hello@paperless-ngx.com",
},
)
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
resp = self.client.post(
f"/api/documents/{doc.pk}/email/",
{
"addresses": "hello@paperless-ngx.com,hello",
"subject": "test",
"message": "hello",
},
)
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
resp = self.client.post(
f"/api/documents/{doc.pk}/email/",
{
"addresses": "hello@paperless-ngx.com",
"subject": "test",
"message": "hello",
},
)
self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
@mock.patch("django_softdelete.models.SoftDeleteModel.delete") @mock.patch("django_softdelete.models.SoftDeleteModel.delete")
def test_warn_on_delete_with_old_uuid_field(self, mocked_delete): def test_warn_on_delete_with_old_uuid_field(self, mocked_delete):
""" """

View File

@@ -1,18 +1,14 @@
import os import os
import tempfile
from pathlib import Path from pathlib import Path
from unittest import mock from unittest import mock
from celery import states
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test import override_settings from django.test import override_settings
from rest_framework import status from rest_framework import status
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
from documents.classifier import ClassifierModelCorruptError from documents.models import PaperlessTask
from documents.classifier import DocumentClassifier
from documents.classifier import load_classifier
from documents.models import Document
from documents.models import Tag
from paperless import version from paperless import version
@@ -193,7 +189,6 @@ class TestSystemStatus(APITestCase):
self.assertEqual(response.data["tasks"]["index_status"], "ERROR") self.assertEqual(response.data["tasks"]["index_status"], "ERROR")
self.assertIsNotNone(response.data["tasks"]["index_error"]) self.assertIsNotNone(response.data["tasks"]["index_error"])
@override_settings(DATA_DIR=Path("/tmp/does_not_exist/data/"))
def test_system_status_classifier_ok(self): def test_system_status_classifier_ok(self):
""" """
GIVEN: GIVEN:
@@ -203,9 +198,11 @@ class TestSystemStatus(APITestCase):
THEN: THEN:
- The response contains an OK classifier status - The response contains an OK classifier status
""" """
load_classifier() PaperlessTask.objects.create(
test_classifier = DocumentClassifier() type=PaperlessTask.TaskType.SCHEDULED_TASK,
test_classifier.save() status=states.SUCCESS,
task_name=PaperlessTask.TaskName.TRAIN_CLASSIFIER,
)
self.client.force_login(self.user) self.client.force_login(self.user)
response = self.client.get(self.ENDPOINT) response = self.client.get(self.ENDPOINT)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
@@ -215,51 +212,34 @@ class TestSystemStatus(APITestCase):
def test_system_status_classifier_warning(self): def test_system_status_classifier_warning(self):
""" """
GIVEN: GIVEN:
- The classifier does not exist yet - No classifier task is found
- > 0 documents and tags with auto matching exist
WHEN: WHEN:
- The user requests the system status - The user requests the system status
THEN: THEN:
- The response contains an WARNING classifier status - The response contains a WARNING classifier status
""" """
with override_settings(MODEL_FILE=Path("does_not_exist")):
Document.objects.create(
title="Test Document",
)
Tag.objects.create(name="Test Tag", matching_algorithm=Tag.MATCH_AUTO)
self.client.force_login(self.user) self.client.force_login(self.user)
response = self.client.get(self.ENDPOINT) response = self.client.get(self.ENDPOINT)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["tasks"]["classifier_status"], "WARNING") self.assertEqual(
self.assertIsNotNone(response.data["tasks"]["classifier_error"]) response.data["tasks"]["classifier_status"],
"WARNING",
@mock.patch(
"documents.classifier.load_classifier",
side_effect=ClassifierModelCorruptError(),
) )
def test_system_status_classifier_error(self, mock_load_classifier):
def test_system_status_classifier_error(self):
""" """
GIVEN: GIVEN:
- The classifier does exist but is corrupt - An error occurred while loading the classifier
- > 0 documents and tags with auto matching exist
WHEN: WHEN:
- The user requests the system status - The user requests the system status
THEN: THEN:
- The response contains an ERROR classifier status - The response contains an ERROR classifier status
""" """
with ( PaperlessTask.objects.create(
tempfile.NamedTemporaryFile( type=PaperlessTask.TaskType.SCHEDULED_TASK,
dir="/tmp", status=states.FAILURE,
delete=False, task_name=PaperlessTask.TaskName.TRAIN_CLASSIFIER,
) as does_exist, result="Classifier training failed",
override_settings(MODEL_FILE=Path(does_exist.name)),
):
Document.objects.create(
title="Test Document",
)
Tag.objects.create(
name="Test Tag",
matching_algorithm=Tag.MATCH_AUTO,
) )
self.client.force_login(self.user) self.client.force_login(self.user)
response = self.client.get(self.ENDPOINT) response = self.client.get(self.ENDPOINT)
@@ -270,18 +250,63 @@ class TestSystemStatus(APITestCase):
) )
self.assertIsNotNone(response.data["tasks"]["classifier_error"]) self.assertIsNotNone(response.data["tasks"]["classifier_error"])
def test_system_status_classifier_ok_no_objects(self): def test_system_status_sanity_check_ok(self):
""" """
GIVEN: GIVEN:
- The classifier does not exist (and should not) - The sanity check is successful
- No documents nor objects with auto matching exist
WHEN: WHEN:
- The user requests the system status - The user requests the system status
THEN: THEN:
- The response contains an OK classifier status - The response contains an OK sanity check status
""" """
with override_settings(MODEL_FILE=Path("does_not_exist")): PaperlessTask.objects.create(
type=PaperlessTask.TaskType.SCHEDULED_TASK,
status=states.SUCCESS,
task_name=PaperlessTask.TaskName.CHECK_SANITY,
)
self.client.force_login(self.user) self.client.force_login(self.user)
response = self.client.get(self.ENDPOINT) response = self.client.get(self.ENDPOINT)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["tasks"]["classifier_status"], "OK") self.assertEqual(response.data["tasks"]["sanity_check_status"], "OK")
self.assertIsNone(response.data["tasks"]["sanity_check_error"])
def test_system_status_sanity_check_warning(self):
"""
GIVEN:
- No sanity check task is found
WHEN:
- The user requests the system status
THEN:
- The response contains a WARNING sanity check status
"""
self.client.force_login(self.user)
response = self.client.get(self.ENDPOINT)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
response.data["tasks"]["sanity_check_status"],
"WARNING",
)
def test_system_status_sanity_check_error(self):
"""
GIVEN:
- The sanity check failed
WHEN:
- The user requests the system status
THEN:
- The response contains an ERROR sanity check status
"""
PaperlessTask.objects.create(
type=PaperlessTask.TaskType.SCHEDULED_TASK,
status=states.FAILURE,
task_name=PaperlessTask.TaskName.CHECK_SANITY,
result="5 issues found.",
)
self.client.force_login(self.user)
response = self.client.get(self.ENDPOINT)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
response.data["tasks"]["sanity_check_status"],
"ERROR",
)
self.assertIsNotNone(response.data["tasks"]["sanity_check_error"])

View File

@@ -130,7 +130,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
) )
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.client.get(self.ENDPOINT) response = self.client.get(self.ENDPOINT + "?acknowledged=false")
self.assertEqual(len(response.data), 0) self.assertEqual(len(response.data), 0)
def test_tasks_owner_aware(self): def test_tasks_owner_aware(self):
@@ -246,7 +246,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
PaperlessTask.objects.create( PaperlessTask.objects.create(
task_id=str(uuid.uuid4()), task_id=str(uuid.uuid4()),
task_file_name="test.pdf", task_file_name="test.pdf",
task_name="documents.tasks.some_task", task_name=PaperlessTask.TaskName.CONSUME_FILE,
status=celery.states.SUCCESS, status=celery.states.SUCCESS,
) )
@@ -272,7 +272,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
PaperlessTask.objects.create( PaperlessTask.objects.create(
task_id=str(uuid.uuid4()), task_id=str(uuid.uuid4()),
task_file_name="anothertest.pdf", task_file_name="anothertest.pdf",
task_name="documents.tasks.some_task", task_name=PaperlessTask.TaskName.CONSUME_FILE,
status=celery.states.SUCCESS, status=celery.states.SUCCESS,
) )

View File

@@ -8,7 +8,7 @@ class TestMigrateWorkflow(TestMigrations):
dependencies = ( dependencies = (
( (
"paperless_mail", "paperless_mail",
"0030_mailrule_stop_processing", "0029_mailrule_pdf_layout",
), ),
) )

View File

@@ -68,7 +68,7 @@ class TestTaskSignalHandler(DirectoriesMixin, TestCase):
self.assertIsNotNone(task) self.assertIsNotNone(task)
self.assertEqual(headers["id"], task.task_id) self.assertEqual(headers["id"], task.task_id)
self.assertEqual("hello-999.pdf", task.task_file_name) self.assertEqual("hello-999.pdf", task.task_file_name)
self.assertEqual("documents.tasks.consume_file", task.task_name) self.assertEqual(PaperlessTask.TaskName.CONSUME_FILE, task.task_name)
self.assertEqual(1, task.owner_id) self.assertEqual(1, task.owner_id)
self.assertEqual(celery.states.PENDING, task.status) self.assertEqual(celery.states.PENDING, task.status)

View File

@@ -15,6 +15,7 @@ from urllib.parse import quote
from urllib.parse import urlparse from urllib.parse import urlparse
import pathvalidate import pathvalidate
from celery import states
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.contrib.auth.models import User from django.contrib.auth.models import User
@@ -37,7 +38,6 @@ from django.http import HttpResponse
from django.http import HttpResponseBadRequest from django.http import HttpResponseBadRequest
from django.http import HttpResponseForbidden from django.http import HttpResponseForbidden
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.http import HttpResponseServerError
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.utils import timezone from django.utils import timezone
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
@@ -104,10 +104,10 @@ from documents.filters import DocumentsOrderingFilter
from documents.filters import DocumentTypeFilterSet from documents.filters import DocumentTypeFilterSet
from documents.filters import ObjectOwnedOrGrantedPermissionsFilter from documents.filters import ObjectOwnedOrGrantedPermissionsFilter
from documents.filters import ObjectOwnedPermissionsFilter from documents.filters import ObjectOwnedPermissionsFilter
from documents.filters import PaperlessTaskFilterSet
from documents.filters import ShareLinkFilterSet from documents.filters import ShareLinkFilterSet
from documents.filters import StoragePathFilterSet from documents.filters import StoragePathFilterSet
from documents.filters import TagFilterSet from documents.filters import TagFilterSet
from documents.mail import send_email
from documents.matching import match_correspondents from documents.matching import match_correspondents
from documents.matching import match_document_types from documents.matching import match_document_types
from documents.matching import match_storage_paths from documents.matching import match_storage_paths
@@ -1025,57 +1025,6 @@ class DocumentViewSet(
return Response(sorted(entries, key=lambda x: x["timestamp"], reverse=True)) return Response(sorted(entries, key=lambda x: x["timestamp"], reverse=True))
@action(methods=["post"], detail=True)
def email(self, request, pk=None):
try:
doc = Document.objects.select_related("owner").get(pk=pk)
if request.user is not None and not has_perms_owner_aware(
request.user,
"view_document",
doc,
):
return HttpResponseForbidden("Insufficient permissions")
except Document.DoesNotExist:
raise Http404
try:
if (
"addresses" not in request.data
or "subject" not in request.data
or "message" not in request.data
):
return HttpResponseBadRequest("Missing required fields")
use_archive_version = request.data.get("use_archive_version", True)
addresses = request.data.get("addresses").split(",")
if not all(
re.match(r"[^@]+@[^@]+\.[^@]+", address.strip())
for address in addresses
):
return HttpResponseBadRequest("Invalid email address found")
send_email(
subject=request.data.get("subject"),
body=request.data.get("message"),
to=addresses,
attachment=(
doc.archive_path
if use_archive_version and doc.has_archive_version
else doc.source_path
),
attachment_mime_type=doc.mime_type,
)
logger.debug(
f"Sent document {doc.id} via email to {addresses}",
)
return Response({"message": "Email sent"})
except Exception as e:
logger.warning(f"An error occurred emailing document: {e!s}")
return HttpResponseServerError(
"Error emailing document, check logs for more detail.",
)
@extend_schema_view( @extend_schema_view(
list=extend_schema( list=extend_schema(
@@ -2277,16 +2226,15 @@ class RemoteVersionView(GenericAPIView):
class TasksViewSet(ReadOnlyModelViewSet): class TasksViewSet(ReadOnlyModelViewSet):
permission_classes = (IsAuthenticated, PaperlessObjectPermissions) permission_classes = (IsAuthenticated, PaperlessObjectPermissions)
serializer_class = TasksViewSerializer serializer_class = TasksViewSerializer
filter_backends = (ObjectOwnedOrGrantedPermissionsFilter,) filter_backends = (
DjangoFilterBackend,
OrderingFilter,
ObjectOwnedOrGrantedPermissionsFilter,
)
filterset_class = PaperlessTaskFilterSet
def get_queryset(self): def get_queryset(self):
queryset = ( queryset = PaperlessTask.objects.all().order_by("-date_created")
PaperlessTask.objects.filter(
acknowledged=False,
)
.order_by("date_created")
.reverse()
)
task_id = self.request.query_params.get("task_id") task_id = self.request.query_params.get("task_id")
if task_id is not None: if task_id is not None:
queryset = PaperlessTask.objects.filter(task_id=task_id) queryset = PaperlessTask.objects.filter(task_id=task_id)
@@ -2615,6 +2563,14 @@ class CustomFieldViewSet(ModelViewSet):
"last_trained": serializers.DateTimeField(), "last_trained": serializers.DateTimeField(),
}, },
), ),
"sanity_check": inline_serializer(
name="SanityCheck",
fields={
"status": serializers.CharField(),
"error": serializers.CharField(),
"last_run": serializers.DateTimeField(),
},
),
}, },
), ),
}, },
@@ -2623,6 +2579,17 @@ class CustomFieldViewSet(ModelViewSet):
class SystemStatusView(PassUserMixin): class SystemStatusView(PassUserMixin):
permission_classes = (IsAuthenticated,) permission_classes = (IsAuthenticated,)
def _get_next_scheduled_task_schedule(
self,
schedule: dict,
task_name: str,
last_run,
) -> datetime | None:
# example: {'Check all e-mail accounts': {'task': 'paperless_mail.tasks.process_mail_accounts', 'schedule': <crontab: */10 * * * * (m/h/dM/MY/d)>, 'options': {'expires': 540.0}}, 'Train the classifier': {'task': 'documents.tasks.train_classifier', 'schedule': <crontab: 5 */1 * * * (m/h/dM/MY/d)>, 'options': {'expires': 3540.0}}, 'Optimize the index': {'task': 'documents.tasks.index_optimize', 'schedule': <crontab: 0 0 * * * (m/h/dM/MY/d)>, 'options': {'expires': 82800.0}}, 'Perform sanity check': {'task': 'documents.tasks.sanity_check', 'schedule': <crontab: 30 0 * * sun (m/h/dM/MY/d)>, 'options': {'expires': 601200.0}}, 'Empty trash': {'task': 'documents.tasks.empty_trash', 'schedule': <crontab: 0 1 * * * (m/h/dM/MY/d)>, 'options': {'expires': 82800.0}}, 'Check and run scheduled workflows': {'task': 'documents.tasks.check_scheduled_workflows', 'schedule': <crontab: 5 */1 * * * (m/h/dM/MY/d)>, 'options': {'expires': 3540.0}}}
for _, task_data in schedule.items():
if task_data["task"] and task_data["task"].find(task_name) != -1:
return task_data["schedule"]
def get(self, request, format=None): def get(self, request, format=None):
if not request.user.is_staff: if not request.user.is_staff:
return HttpResponseForbidden("Insufficient permissions") return HttpResponseForbidden("Insufficient permissions")
@@ -2675,13 +2642,22 @@ class SystemStatusView(PassUserMixin):
) )
redis_error = "Error connecting to redis, check logs for more detail." redis_error = "Error connecting to redis, check logs for more detail."
celery_error = None
celery_url = None
schedule = None
try: try:
celery_ping = celery_app.control.inspect().ping() celery_ping = celery_app.control.inspect().ping()
first_worker_ping = celery_ping[next(iter(celery_ping.keys()))] celery_url = next(iter(celery_ping.keys()))
first_worker_ping = celery_ping[celery_url]
schedule = celery_app.conf.beat_schedule
if first_worker_ping["ok"] == "pong": if first_worker_ping["ok"] == "pong":
celery_active = "OK" celery_active = "OK"
except Exception: except Exception as e:
celery_active = "ERROR" celery_active = "ERROR"
logger.exception(
f"System status detected a possible problem while connecting to celery: {e}",
)
celery_error = "Error connecting to celery, check logs for more detail."
index_error = None index_error = None
try: try:
@@ -2698,54 +2674,72 @@ class SystemStatusView(PassUserMixin):
) )
index_last_modified = None index_last_modified = None
classifier_error = None last_trained_task = (
classifier_status = None PaperlessTask.objects.filter(
try: task_name=PaperlessTask.TaskName.TRAIN_CLASSIFIER,
classifier = load_classifier(raise_exception=True)
if classifier is None:
# Make sure classifier should exist
docs_queryset = Document.objects.exclude(
tags__is_inbox_tag=True,
) )
if ( .order_by("-date_done")
docs_queryset.count() > 0 .first()
and (
Tag.objects.filter(matching_algorithm=Tag.MATCH_AUTO).exists()
or DocumentType.objects.filter(
matching_algorithm=Tag.MATCH_AUTO,
).exists()
or Correspondent.objects.filter(
matching_algorithm=Tag.MATCH_AUTO,
).exists()
or StoragePath.objects.filter(
matching_algorithm=Tag.MATCH_AUTO,
).exists()
) )
and not settings.MODEL_FILE.exists()
):
# if classifier file doesn't exist just classify as a warning
classifier_error = "Classifier file does not exist (yet). Re-training may be pending."
classifier_status = "WARNING"
raise FileNotFoundError(classifier_error)
classifier_status = "OK" classifier_status = "OK"
classifier_last_trained = ( classifier_error = None
make_aware( classifier_next_training = None
datetime.fromtimestamp(classifier.get_last_checked()), if last_trained_task is None:
) classifier_status = "WARNING"
if settings.MODEL_FILE.exists() classifier_error = "No classifier training tasks found"
and classifier.get_last_checked() is not None elif last_trained_task and last_trained_task.status == states.FAILURE:
else None
)
except Exception as e:
if classifier_status is None:
classifier_status = "ERROR" classifier_status = "ERROR"
classifier_last_trained = None classifier_error = last_trained_task.result
if classifier_error is None: classifier_last_trained = (
classifier_error = ( last_trained_task.date_done if last_trained_task else None
"Unable to load classifier, check logs for more detail."
) )
logger.exception( last_scheduled_trained_task = (
f"System status detected a possible problem while loading the classifier: {e}", PaperlessTask.objects.filter(
task_name=PaperlessTask.TaskName.TRAIN_CLASSIFIER,
type=PaperlessTask.TaskType.SCHEDULED_TASK,
)
.order_by("-date_done")
.first()
)
if last_scheduled_trained_task and schedule:
classifier_next_training: datetime = self._get_next_scheduled_task_schedule(
schedule=schedule,
task_name=PaperlessTask.TaskName.TRAIN_CLASSIFIER,
last_run=last_trained_task.date_done,
)
last_sanity_check = (
PaperlessTask.objects.filter(
task_name=PaperlessTask.TaskName.CHECK_SANITY,
)
.order_by("-date_done")
.first()
)
sanity_check_status = "OK"
sanity_check_error = None
sanity_check_next_run = None
if last_sanity_check is None:
sanity_check_status = "WARNING"
sanity_check_error = "No sanity check tasks found"
elif last_sanity_check and last_sanity_check.status == states.FAILURE:
sanity_check_status = "ERROR"
sanity_check_error = last_sanity_check.result
sanity_check_last_run = (
last_sanity_check.date_done if last_sanity_check else None
)
last_scheduled_sanity_check = (
PaperlessTask.objects.filter(
task_name=PaperlessTask.TaskName.CHECK_SANITY,
type=PaperlessTask.TaskType.SCHEDULED_TASK,
)
.order_by("-date_done")
.first()
)
if last_scheduled_sanity_check and schedule:
sanity_check_next_run: datetime = self._get_next_scheduled_task_schedule(
schedule=schedule,
task_name=PaperlessTask.TaskName.CHECK_SANITY,
last_run=last_sanity_check.date_done,
) )
return Response( return Response(
@@ -2774,12 +2768,19 @@ class SystemStatusView(PassUserMixin):
"redis_status": redis_status, "redis_status": redis_status,
"redis_error": redis_error, "redis_error": redis_error,
"celery_status": celery_active, "celery_status": celery_active,
"celery_url": celery_url,
"celery_error": celery_error,
"index_status": index_status, "index_status": index_status,
"index_last_modified": index_last_modified, "index_last_modified": index_last_modified,
"index_error": index_error, "index_error": index_error,
"classifier_status": classifier_status, "classifier_status": classifier_status,
"classifier_last_trained": classifier_last_trained, "classifier_last_trained": classifier_last_trained,
"classifier_next_training": classifier_next_training,
"classifier_error": classifier_error, "classifier_error": classifier_error,
"sanity_check_status": sanity_check_status,
"sanity_check_last_run": sanity_check_last_run,
"sanity_check_next_run": sanity_check_next_run,
"sanity_check_error": sanity_check_error,
}, },
}, },
) )

File diff suppressed because it is too large Load Diff

View File

@@ -571,11 +571,6 @@ class MailAccountHandler(LoggingMixin):
rule, rule,
supports_gmail_labels=supports_gmail_labels, supports_gmail_labels=supports_gmail_labels,
) )
if total_processed_files > 0 and rule.stop_processing:
self.log.debug(
f"Rule {rule}: Stopping processing rules due to stop_processing flag",
)
break
except Exception as e: except Exception as e:
self.log.exception( self.log.exception(
f"Rule {rule}: Error while processing rule: {e}", f"Rule {rule}: Error while processing rule: {e}",

View File

@@ -1,22 +0,0 @@
# Generated by Django 5.1.6 on 2025-02-24 16:07
from django.db import migrations
from django.db import models
class Migration(migrations.Migration):
dependencies = [
("paperless_mail", "0029_mailrule_pdf_layout"),
]
operations = [
migrations.AddField(
model_name="mailrule",
name="stop_processing",
field=models.BooleanField(
default=False,
help_text="If True, no further rules will be processed after this one if any document is consumed.",
verbose_name="Stop processing further rules",
),
),
]

View File

@@ -301,14 +301,6 @@ class MailRule(document_models.ModelWithOwner):
default=True, default=True,
) )
stop_processing = models.BooleanField(
_("Stop processing further rules"),
default=False,
help_text=_(
"If True, no further rules will be processed after this one if any document is queued.",
),
)
def __str__(self): def __str__(self):
return f"{self.account.name}.{self.name}" return f"{self.account.name}.{self.name}"

View File

@@ -101,7 +101,6 @@ class MailRuleSerializer(OwnedObjectSerializer):
"user_can_change", "user_can_change",
"permissions", "permissions",
"set_permissions", "set_permissions",
"stop_processing",
] ]
def update(self, instance, validated_data): def update(self, instance, validated_data):

View File

@@ -1671,39 +1671,6 @@ class TestTasks(TestCase):
result = tasks.process_mail_accounts(account_ids=[account_b.id]) result = tasks.process_mail_accounts(account_ids=[account_b.id])
self.assertIn("No new", result) self.assertIn("No new", result)
@mock.patch("paperless_mail.tasks.MailAccountHandler.handle_mail_account")
def test_rule_with_stop_processing(self, m):
"""
GIVEN:
- Mail account with a rule with stop_processing=True
WHEN:
- Mail account is processed
THEN:
- Should only process the first rule
"""
m.side_effect = lambda account: 6
account = MailAccount.objects.create(
name="A",
imap_server="A",
username="A",
password="A",
)
MailRule.objects.create(
name="A",
account=account,
stop_processing=True,
)
MailRule.objects.create(
name="B",
account=account,
)
result = tasks.process_mail_accounts()
self.assertEqual(m.call_count, 1)
self.assertIn("Added 6", result)
class TestMailAccountTestView(APITestCase): class TestMailAccountTestView(APITestCase):
def setUp(self): def setUp(self):