diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts index 3c3a67aeb..a62c98d6a 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.ts @@ -793,11 +793,30 @@ export class DocumentDetailComponent }) } + private getChangedFields(): any { + const changes = { + id: this.document.id, + } + Object.keys(this.documentForm.controls).forEach((key) => { + if (this.documentForm.get(key).dirty) { + if (key === 'permissions_form') { + changes['owner'] = + this.documentForm.get('permissions_form').value['owner'] + changes['set_permissions'] = + this.documentForm.get('permissions_form').value['set_permissions'] + } else { + changes[key] = this.documentForm.get(key).value + } + } + }) + return changes + } + save(close: boolean = false) { this.networkActive = true ;(document.activeElement as HTMLElement)?.dispatchEvent(new Event('change')) this.documentsService - .patch(this.document) + .patch(this.getChangedFields()) .pipe(first()) .subscribe({ next: (docValues) => { @@ -851,7 +870,7 @@ export class DocumentDetailComponent this.networkActive = true this.store.next(this.documentForm.value) this.documentsService - .patch(this.document) + .patch(this.getChangedFields()) .pipe( switchMap((updateResult) => { return this.documentListViewService @@ -1304,6 +1323,8 @@ export class DocumentDetailComponent created: new Date(), }) this.updateFormForCustomFields(true) + this.documentForm.get('custom_fields').markAsDirty() + this.documentForm.updateValueAndValidity() } public removeField(fieldInstance: CustomFieldInstance) { @@ -1312,6 +1333,7 @@ export class DocumentDetailComponent 1 ) this.updateFormForCustomFields(true) + this.documentForm.get('custom_fields').markAsDirty() this.documentForm.updateValueAndValidity() } diff --git a/src-ui/src/app/services/rest/document.service.spec.ts b/src-ui/src/app/services/rest/document.service.spec.ts index 84f7f6f8a..9480e2816 100644 --- a/src-ui/src/app/services/rest/document.service.spec.ts +++ b/src-ui/src/app/services/rest/document.service.spec.ts @@ -268,15 +268,15 @@ describe(`DocumentService`, () => { expect(req.request.method).toEqual('GET') }) - it('should pass remove_inbox_tags setting to update', () => { - subscription = service.update(documents[0]).subscribe() + it('should pass remove_inbox_tags setting to patch', () => { + subscription = service.patch(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() + subscription = service.patch(documents[0]).subscribe() req = httpTestingController.expectOne( `${environment.apiBaseUrl}${endpoint}/${documents[0].id}/` ) diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts index 0c6c8cfa6..9cdb86280 100644 --- a/src-ui/src/app/services/rest/document.service.ts +++ b/src-ui/src/app/services/rest/document.service.ts @@ -189,13 +189,13 @@ export class DocumentService extends AbstractPaperlessService { return this.http.get(this.getResourceUrl(null, 'next_asn')) } - update(o: Document): Observable { + patch(o: Document): Observable { // we want to only set created_date - o.created = undefined + delete o.created o.remove_inbox_tags = !!this.settingsService.get( SETTINGS_KEYS.DOCUMENT_EDITING_REMOVE_INBOX_TAGS ) - return super.update(o) + return super.patch(o) } uploadDocument(formData) {