mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Feature: option for auto-remove inbox tags on save (#5562)
This commit is contained in:
@@ -7,10 +7,13 @@ import { TestBed } from '@angular/core/testing'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { DocumentService } from './document.service'
|
||||
import { FILTER_TITLE } from 'src/app/data/filter-rule-type'
|
||||
import { SettingsService } from '../settings.service'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
|
||||
let httpTestingController: HttpTestingController
|
||||
let service: DocumentService
|
||||
let subscription: Subscription
|
||||
let settingsService: SettingsService
|
||||
const endpoint = 'documents'
|
||||
const documents = [
|
||||
{
|
||||
@@ -34,6 +37,17 @@ const documents = [
|
||||
},
|
||||
]
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [DocumentService],
|
||||
imports: [HttpClientTestingModule],
|
||||
})
|
||||
|
||||
httpTestingController = TestBed.inject(HttpTestingController)
|
||||
service = TestBed.inject(DocumentService)
|
||||
settingsService = TestBed.inject(SettingsService)
|
||||
})
|
||||
|
||||
describe(`DocumentService`, () => {
|
||||
// common tests e.g. commonAbstractPaperlessServiceTests differ slightly
|
||||
it('should call appropriate api endpoint for list all', () => {
|
||||
@@ -237,16 +251,21 @@ describe(`DocumentService`, () => {
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [DocumentService],
|
||||
imports: [HttpClientTestingModule],
|
||||
it('should pass remove_inbox_tags setting to update', () => {
|
||||
subscription = service.update(documents[0]).subscribe()
|
||||
let req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}${endpoint}/${documents[0].id}/`
|
||||
)
|
||||
expect(req.request.body.remove_inbox_tags).toEqual(false)
|
||||
|
||||
settingsService.set(SETTINGS_KEYS.DOCUMENT_EDITING_REMOVE_INBOX_TAGS, true)
|
||||
subscription = service.update(documents[0]).subscribe()
|
||||
req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}${endpoint}/${documents[0].id}/`
|
||||
)
|
||||
expect(req.request.body.remove_inbox_tags).toEqual(true)
|
||||
})
|
||||
|
||||
httpTestingController = TestBed.inject(HttpTestingController)
|
||||
service = TestBed.inject(DocumentService)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
|
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'
|
||||
import { Document } from 'src/app/data/document'
|
||||
import { DocumentMetadata } from 'src/app/data/document-metadata'
|
||||
import { AbstractPaperlessService } from './abstract-paperless-service'
|
||||
import { HttpClient, HttpParams } from '@angular/common/http'
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Observable } from 'rxjs'
|
||||
import { Results } from 'src/app/data/results'
|
||||
import { FilterRule } from 'src/app/data/filter-rule'
|
||||
@@ -18,6 +18,8 @@ import {
|
||||
PermissionType,
|
||||
PermissionsService,
|
||||
} from '../permissions.service'
|
||||
import { SettingsService } from '../settings.service'
|
||||
import { SETTINGS, SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
|
||||
export const DOCUMENT_SORT_FIELDS = [
|
||||
{ field: 'archive_serial_number', name: $localize`ASN` },
|
||||
@@ -63,7 +65,8 @@ export class DocumentService extends AbstractPaperlessService<Document> {
|
||||
private documentTypeService: DocumentTypeService,
|
||||
private tagService: TagService,
|
||||
private storagePathService: StoragePathService,
|
||||
private permissionsService: PermissionsService
|
||||
private permissionsService: PermissionsService,
|
||||
private settingsService: SettingsService
|
||||
) {
|
||||
super(http, 'documents')
|
||||
}
|
||||
@@ -180,6 +183,9 @@ export class DocumentService extends AbstractPaperlessService<Document> {
|
||||
update(o: Document): Observable<Document> {
|
||||
// we want to only set created_date
|
||||
o.created = undefined
|
||||
o.remove_inbox_tags = this.settingsService.get(
|
||||
SETTINGS_KEYS.DOCUMENT_EDITING_REMOVE_INBOX_TAGS
|
||||
)
|
||||
return super.update(o)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user