A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Enhancement: warn when outdated doc detected (#5372)
shamoon53e04e66cf52
diff --git a/src-ui/messages.xlf b/src-ui/messages.xlfindex d2fd2a0b1..a3e9b3330 100644--- a/src-ui/messages.xlf+++ b/src-ui/messages.xlf@@ -1931,7 +1931,7 @@</context-group><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">688</context>+ <context context-type="linenumber">701</context></context-group><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.ts</context>@@ -1970,7 +1970,7 @@</context-group><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">690</context>+ <context context-type="linenumber">703</context></context-group><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.ts</context>@@ -2394,13 +2394,6 @@<context context-type="linenumber">63</context></context-group></trans-unit>- <trans-unit id="5000042972069710005" datatype="html">- <source><x id="START_TAG_SPAN" ctype="x-span" equiv-text="<span class="d-inline-block" style="padding-bottom: 1px;" >"/>Cancel<x id="CLOSE_TAG_SPAN" ctype="x-span" equiv-text="</span>"/></source>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/confirm-dialog/confirm-dialog.component.html</context>- <context context-type="linenumber">16</context>- </context-group>- </trans-unit><trans-unit id="1234709746630139322" datatype="html"><source>Confirmation</source><context-group purpose="location">@@ -2435,6 +2428,73 @@<context context-type="linenumber">439</context></context-group></trans-unit>+ <trans-unit id="2159130950882492111" datatype="html">+ <source>Cancel</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/confirm-dialog/confirm-dialog.component.ts</context>+ <context context-type="linenumber">44</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component.html</context>+ <context context-type="linenumber">24</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.html</context>+ <context context-type="linenumber">15</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component.html</context>+ <context context-type="linenumber">26</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/edit-dialog/group-edit-dialog/group-edit-dialog.component.html</context>+ <context context-type="linenumber">16</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component.html</context>+ <context context-type="linenumber">36</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html</context>+ <context context-type="linenumber">48</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component.html</context>+ <context context-type="linenumber">25</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/edit-dialog/tag-edit-dialog/tag-edit-dialog.component.html</context>+ <context context-type="linenumber">27</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.html</context>+ <context context-type="linenumber">35</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html</context>+ <context context-type="linenumber">170</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/permissions-dialog/permissions-dialog.component.html</context>+ <context context-type="linenumber">22</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>+ <context context-type="linenumber">57</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/common/select-dialog/select-dialog.component.html</context>+ <context context-type="linenumber">12</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.html</context>+ <context context-type="linenumber">6</context>+ </context-group>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.html</context>+ <context context-type="linenumber">20</context>+ </context-group>+ </trans-unit><trans-unit id="3972154626835212608" datatype="html"><source>Create New Field</source><context-group purpose="location">@@ -2599,69 +2659,6 @@<context context-type="linenumber">194</context></context-group></trans-unit>- <trans-unit id="2159130950882492111" datatype="html">- <source>Cancel</source>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component.html</context>- <context context-type="linenumber">24</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.html</context>- <context context-type="linenumber">15</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component.html</context>- <context context-type="linenumber">26</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/edit-dialog/group-edit-dialog/group-edit-dialog.component.html</context>- <context context-type="linenumber">16</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component.html</context>- <context context-type="linenumber">36</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html</context>- <context context-type="linenumber">48</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component.html</context>- <context context-type="linenumber">25</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/edit-dialog/tag-edit-dialog/tag-edit-dialog.component.html</context>- <context context-type="linenumber">27</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/edit-dialog/user-edit-dialog/user-edit-dialog.component.html</context>- <context context-type="linenumber">35</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/edit-dialog/workflow-edit-dialog/workflow-edit-dialog.component.html</context>- <context context-type="linenumber">170</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/permissions-dialog/permissions-dialog.component.html</context>- <context context-type="linenumber">22</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/profile-edit-dialog/profile-edit-dialog.component.html</context>- <context context-type="linenumber">57</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/common/select-dialog/select-dialog.component.html</context>- <context context-type="linenumber">12</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.html</context>- <context context-type="linenumber">6</context>- </context-group>- <context-group purpose="location">- <context context-type="sourcefile">src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.html</context>- <context context-type="linenumber">20</context>- </context-group>- </trans-unit><trans-unit id="6457471243969293847" datatype="html"><source>Create new correspondent</source><context-group purpose="location">@@ -4793,47 +4790,75 @@<context context-type="linenumber">276,278</context></context-group></trans-unit>+ <trans-unit id="3200733026060976258" datatype="html">+ <source>Document changes detected</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>+ <context context-type="linenumber">298</context>+ </context-group>+ </trans-unit>+ <trans-unit id="2887155916749964" datatype="html">+ <source>The version of this document in your browser session appears older than the existing version.</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>+ <context context-type="linenumber">299</context>+ </context-group>+ </trans-unit>+ <trans-unit id="237142428785956348" datatype="html">+ <source>Saving the document here may overwrite other changes that were made. To restore the existing version, discard your changes or close the document.</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>+ <context context-type="linenumber">300</context>+ </context-group>+ </trans-unit>+ <trans-unit id="8720977247725652816" datatype="html">+ <source>Ok</source>+ <context-group purpose="location">+ <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>+ <context context-type="linenumber">301</context>+ </context-group>+ </trans-unit><trans-unit id="5758784066858623886" datatype="html"><source>Error retrieving metadata</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">424</context>+ <context context-type="linenumber">437</context></context-group></trans-unit><trans-unit id="3456881259945295697" datatype="html"><source>Error retrieving suggestions.</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">445</context>+ <context context-type="linenumber">458</context></context-group></trans-unit><trans-unit id="8348337312757497317" datatype="html"><source>Document saved successfully.</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">563</context>+ <context context-type="linenumber">576</context></context-group><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">572</context>+ <context context-type="linenumber">585</context></context-group></trans-unit><trans-unit id="448882439049417053" datatype="html"><source>Error saving document</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">576</context>+ <context context-type="linenumber">589</context></context-group><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">617</context>+ <context context-type="linenumber">630</context></context-group></trans-unit><trans-unit id="9021887951960049161" datatype="html"><source>Confirm delete</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">643</context>+ <context context-type="linenumber">656</context></context-group><context-group purpose="location"><context context-type="sourcefile">src/app/components/manage/management-list/management-list.component.ts</context>@@ -4844,35 +4869,35 @@<source>Do you really want to delete document "<x id="PH" equiv-text="this.document.title"/>"?</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">644</context>+ <context context-type="linenumber">657</context></context-group></trans-unit><trans-unit id="6691075929777935948" datatype="html"><source>The files for this document will be deleted permanently. This operation cannot be undone.</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">645</context>+ <context context-type="linenumber">658</context></context-group></trans-unit><trans-unit id="719892092227206532" datatype="html"><source>Delete document</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">647</context>+ <context context-type="linenumber">660</context></context-group></trans-unit><trans-unit id="7295637485862454066" datatype="html"><source>Error deleting document</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">666</context>+ <context context-type="linenumber">679</context></context-group></trans-unit><trans-unit id="7362691899087997122" datatype="html"><source>Redo OCR confirm</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">686</context>+ <context context-type="linenumber">699</context></context-group><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.ts</context>@@ -4883,28 +4908,28 @@<source>This operation will permanently redo OCR for this document.</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">687</context>+ <context context-type="linenumber">700</context></context-group></trans-unit><trans-unit id="5729001209753056399" datatype="html"><source>Redo OCR operation will begin in the background. Close and re-open or reload this document after the operation has completed to see new content.</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">698</context>+ <context context-type="linenumber">711</context></context-group></trans-unit><trans-unit id="4409560272830824468" datatype="html"><source>Error executing operation</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">709</context>+ <context context-type="linenumber">722</context></context-group></trans-unit><trans-unit id="4458954481601077369" datatype="html"><source>Page Fit</source><context-group purpose="location"><context context-type="sourcefile">src/app/components/document-detail/document-detail.component.ts</context>- <context context-type="linenumber">778</context>+ <context context-type="linenumber">791</context></context-group></trans-unit><trans-unit id="6857598786757174736" datatype="html">diff --git a/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.html b/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.htmlindex bb5577061..e25ace612 100644--- a/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.html+++ b/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.html@@ -12,8 +12,8 @@}</div><div class="modal-footer">- <button type="button" class="btn btn-outline-secondary" (click)="cancel()" [disabled]="!buttonsEnabled" i18n>- <span class="d-inline-block" style="padding-bottom: 1px;" >Cancel</span>+ <button type="button" class="btn" [class]="cancelBtnClass" (click)="cancel()" [disabled]="!buttonsEnabled">+ <span class="d-inline-block" style="padding-bottom: 1px;">{{cancelBtnCaption}}</span></button><button type="button" class="btn" [class]="btnClass" (click)="confirm()" [disabled]="!confirmButtonEnabled || !buttonsEnabled"><span>diff --git a/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.ts b/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.tsindex 4ab2af257..9c627ead0 100644--- a/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.ts+++ b/src-ui/src/app/components/common/confirm-dialog/confirm-dialog.component.ts@@ -37,6 +37,12 @@ export class ConfirmDialogComponent {@Input()alternativeBtnCaption+ @Input()+ cancelBtnClass = 'btn-outline-secondary'++ @Input()+ cancelBtnCaption = $localize`Cancel`+@Input()buttonsEnabled = truediff --git a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts b/src-ui/src/app/components/document-detail/document-detail.component.spec.tsindex d37fa852a..1492c3e0e 100644--- a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts+++ b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts@@ -79,8 +79,9 @@ const doc: Document = {storage_path: 31,tags: [41, 42, 43],content: 'text content',- added: new Date(),- created: new Date(),+ added: new Date('May 4, 2014 03:24:00'),+ created: new Date('May 4, 2014 03:24:00'),+ modified: new Date('May 4, 2014 03:24:00'),archive_serial_number: null,original_file_name: 'file.pdf',owner: null,@@ -935,6 +936,26 @@ describe('DocumentDetailComponent', () => {expect(refreshSpy).toHaveBeenCalled()})+ it('should warn when open document does not match doc retrieved from backend on init', () => {+ const modalSpy = jest.spyOn(modalService, 'open')+ const openDoc = Object.assign({}, doc)+ // simulate a document being modified elsewhere and db updated+ doc.modified = new Date()+ jest.spyOn(documentService, 'get').mockReturnValueOnce(of(doc))+ jest.spyOn(openDocumentsService, 'getOpenDocument').mockReturnValue(openDoc)+ jest.spyOn(customFieldsService, 'listAll').mockReturnValue(+ of({+ count: customFields.length,+ all: customFields.map((f) => f.id),+ results: customFields,+ })+ )+ fixture.detectChanges() // calls ngOnInit+ expect(modalSpy).toHaveBeenCalledWith(ConfirmDialogComponent, {+ backdrop: 'static',+ })+ })+function initNormally() {jest.spyOn(documentService, 'get')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.tsindex edc19ec70..83057b8cd 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@@ -289,7 +289,23 @@ export class DocumentDetailComponentconst openDocument = this.openDocumentService.getOpenDocument(this.documentId)+if (openDocument) {+ if (+ new Date(doc.modified) > new Date(openDocument.modified) &&+ !this.modalService.hasOpenModals()+ ) {+ let modal = this.modalService.open(ConfirmDialogComponent, {+ backdrop: 'static',+ })+ modal.componentInstance.title = $localize`Document changes detected`+ modal.componentInstance.messageBold = $localize`The version of this document in your browser session appears older than the existing version.`+ modal.componentInstance.message = $localize`Saving the document here may overwrite other changes that were made. To restore the existing version, discard your changes or close the document.`+ modal.componentInstance.cancelBtnCaption = $localize`Ok`+ modal.componentInstance.cancelBtnClass = 'btn-primary'+ modal.componentInstance.btnClass = 'visually-hidden'+ }+if (this.documentForm.dirty) {Object.assign(openDocument, this.documentForm.value)openDocument['owner'] =diff --git a/src/documents/serialisers.py b/src/documents/serialisers.pyindex ffcfbcc1d..34d842443 100644--- a/src/documents/serialisers.py+++ b/src/documents/serialisers.py@@ -13,6 +13,7 @@ from django.contrib.contenttypes.models import ContentTypefrom django.core.validators import DecimalValidatorfrom django.core.validators import MaxLengthValidatorfrom django.core.validators import integer_validator+from django.utils import timezonefrom django.utils.crypto import get_random_stringfrom django.utils.text import slugifyfrom django.utils.translation import gettext as _@@ -580,6 +581,7 @@ class CustomFieldInstanceSerializer(serializers.ModelSerializer):custom_field_instances_to_update,["value_document_ids"],)+ Document.objects.filter(id__in=target_doc_ids).update(modified=timezone.now())@staticmethoddef remove_doclink(@@ -600,6 +602,7 @@ class CustomFieldInstanceSerializer(serializers.ModelSerializer):):target_doc_field_instance.value.remove(document.id)target_doc_field_instance.save()+ Document.objects.filter(id=target_doc_id).update(modified=timezone.now())class Meta:model = CustomFieldInstance