From f3438914ccd1b937ce46e42ac66d4877256b467c Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 14 Feb 2025 15:39:10 -0800 Subject: [PATCH] Support acknowledged param --- .../admin/tasks/tasks.component.spec.ts | 4 ++- src-ui/src/app/services/tasks.service.spec.ts | 10 ++++--- src-ui/src/app/services/tasks.service.ts | 4 ++- src/documents/filters.py | 5 ++++ src/documents/serialisers.py | 29 ++++++++++--------- src/documents/views.py | 8 +---- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts b/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts index 648c93cd3..8158be7b2 100644 --- a/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts +++ b/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts @@ -162,7 +162,9 @@ describe('TasksComponent', () => { jest.useFakeTimers() fixture.detectChanges() httpTestingController - .expectOne(`${environment.apiBaseUrl}tasks/?task_name=consume_file`) + .expectOne( + `${environment.apiBaseUrl}tasks/?task_name=consume_file&acknowledged=false` + ) .flush(tasks) }) diff --git a/src-ui/src/app/services/tasks.service.spec.ts b/src-ui/src/app/services/tasks.service.spec.ts index bb18b5216..940690453 100644 --- a/src-ui/src/app/services/tasks.service.spec.ts +++ b/src-ui/src/app/services/tasks.service.spec.ts @@ -37,7 +37,7 @@ describe('TasksService', () => { it('calls tasks api endpoint on reload', () => { tasksService.reload() const req = httpTestingController.expectOne( - `${environment.apiBaseUrl}tasks/?task_name=consume_file` + `${environment.apiBaseUrl}tasks/?task_name=consume_file&acknowledged=false` ) expect(req.request.method).toEqual('GET') }) @@ -46,7 +46,7 @@ describe('TasksService', () => { tasksService.loading = true tasksService.reload() httpTestingController.expectNone( - `${environment.apiBaseUrl}tasks/?task_name=consume_file` + `${environment.apiBaseUrl}tasks/?task_name=consume_file&acknowledged=false` ) }) @@ -62,7 +62,9 @@ describe('TasksService', () => { req.flush([]) // reload is then called httpTestingController - .expectOne(`${environment.apiBaseUrl}tasks/?task_name=consume_file`) + .expectOne( + `${environment.apiBaseUrl}tasks/?task_name=consume_file&acknowledged=false` + ) .flush([]) }) @@ -119,7 +121,7 @@ describe('TasksService', () => { tasksService.reload() const req = httpTestingController.expectOne( - `${environment.apiBaseUrl}tasks/?task_name=consume_file` + `${environment.apiBaseUrl}tasks/?task_name=consume_file&acknowledged=false` ) req.flush(mockTasks) diff --git a/src-ui/src/app/services/tasks.service.ts b/src-ui/src/app/services/tasks.service.ts index 51db7e48c..e499a0dd8 100644 --- a/src-ui/src/app/services/tasks.service.ts +++ b/src-ui/src/app/services/tasks.service.ts @@ -54,7 +54,9 @@ export class TasksService { this.loading = true this.http - .get(`${this.baseUrl}tasks/?task_name=consume_file`) + .get( + `${this.baseUrl}tasks/?task_name=consume_file&acknowledged=false` + ) .pipe(takeUntil(this.unsubscribeNotifer), first()) .subscribe((r) => { this.fileTasks = r.filter((t) => t.type == PaperlessTaskType.Auto) diff --git a/src/documents/filters.py b/src/documents/filters.py index 19b4d95b6..6c2214de2 100644 --- a/src/documents/filters.py +++ b/src/documents/filters.py @@ -772,6 +772,11 @@ class ShareLinkFilterSet(FilterSet): class PaperlessTaskFilterSet(FilterSet): + acknowledged = BooleanFilter( + label="Acknowledged", + field_name="acknowledged", + ) + class Meta: model = PaperlessTask fields = { diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 5bab41b26..d93b0a65f 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -1708,20 +1708,21 @@ class TasksViewSerializer(OwnedObjectSerializer): def get_related_document(self, obj) -> str | None: result = None re = None - match obj.status: - case states.SUCCESS: - re = self.created_doc_re - case states.FAILURE: - re = ( - self.duplicate_doc_re - if "existing document is in the trash" not in obj.result - else None - ) - if re is not None: - try: - result = re.search(obj.result).group(1) - except Exception: - pass + if obj.result: + match obj.status: + case states.SUCCESS: + re = self.created_doc_re + case states.FAILURE: + re = ( + self.duplicate_doc_re + if "existing document is in the trash" not in obj.result + else None + ) + if re is not None: + try: + result = re.search(obj.result).group(1) + except Exception: + pass return result diff --git a/src/documents/views.py b/src/documents/views.py index 43984e578..bab20230d 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -2233,13 +2233,7 @@ class TasksViewSet(ReadOnlyModelViewSet): filterset_class = PaperlessTaskFilterSet def get_queryset(self): - queryset = ( - PaperlessTask.objects.filter( - acknowledged=False, - ) - .order_by("date_created") - .reverse() - ) + queryset = PaperlessTask.objects.all().order_by("date_created").reverse() task_id = self.request.query_params.get("task_id") if task_id is not None: queryset = PaperlessTask.objects.filter(task_id=task_id)