Compare commits

...
9 changed files with 153 additions and 30 deletions
+13 -17
View File
@@ -2749,7 +2749,7 @@
</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">169</context>
<context context-type="linenumber">179</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/manage/document-attributes/custom-fields/custom-fields.component.html</context>
@@ -3600,11 +3600,11 @@
</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">132</context>
<context context-type="linenumber">142</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">141</context>
<context context-type="linenumber">151</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/document-card-large/document-card-large.component.html</context>
@@ -5350,7 +5350,7 @@
</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">126</context>
<context context-type="linenumber">136</context>
</context-group>
</trans-unit>
<trans-unit id="5342432350421167093" datatype="html">
@@ -6512,10 +6512,6 @@
<context context-type="sourcefile">src/app/components/common/input/document-link/document-link.component.html</context>
<context context-type="linenumber">43</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/input/document-link/document-link.component.html</context>
<context context-type="linenumber">50</context>
</context-group>
</trans-unit>
<trans-unit id="1388712764439031120" datatype="html">
<source>Open link</source>
@@ -6528,8 +6524,8 @@
<context context-type="linenumber">14</context>
</context-group>
</trans-unit>
<trans-unit id="6595008830732269870" datatype="html">
<source>Not found</source>
<trans-unit id="5643561794785412000" datatype="html">
<source>Unavailable</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/input/document-link/document-link.component.html</context>
<context context-type="linenumber">51,52</context>
@@ -7384,7 +7380,7 @@
</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">121</context>
<context context-type="linenumber">124</context>
</context-group>
</trans-unit>
<trans-unit id="1070687661569746428" datatype="html">
@@ -8216,7 +8212,7 @@
</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">144</context>
<context context-type="linenumber">154</context>
</context-group>
</trans-unit>
<trans-unit id="8659635229098859487" datatype="html">
@@ -8234,7 +8230,7 @@
</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">160,161</context>
<context context-type="linenumber">170,171</context>
</context-group>
</trans-unit>
<trans-unit id="2696010339872056565" datatype="html">
@@ -9068,28 +9064,28 @@
<source>Create a share link bundle</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.html</context>
<context context-type="linenumber">118</context>
<context context-type="linenumber">119</context>
</context-group>
</trans-unit>
<trans-unit id="1015374532025907183" datatype="html">
<source>Include:</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.html</context>
<context context-type="linenumber">147,148</context>
<context context-type="linenumber">157,158</context>
</context-group>
</trans-unit>
<trans-unit id="1537670659786159738" datatype="html">
<source>Archived files</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.html</context>
<context context-type="linenumber">151,152</context>
<context context-type="linenumber">161,162</context>
</context-group>
</trans-unit>
<trans-unit id="2520291319362448498" datatype="html">
<source>Original files</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/bulk-editor/bulk-editor.component.html</context>
<context context-type="linenumber">155,156</context>
<context context-type="linenumber">165,166</context>
</context-group>
</trans-unit>
<trans-unit id="1215215387232313677" datatype="html">
@@ -47,8 +47,8 @@
<i-bs width="0.9em" height="0.9em" name="file-text" class="me-1"></i-bs><span>{{document.title}}</span>
</a>
} @else {
<span class="badge bg-light text-muted" (click)="unselect(document)" (mousedown)="$event.stopImmediatePropagation()" type="button" title="Remove link" i18n-title>
<i-bs width="0.9em" height="0.9em" name="exclamation-triangle-fill" class="me-1"></i-bs><span i18n>Not found</span>
<span class="badge bg-light text-muted">
<i-bs width="0.9em" height="0.9em" name="exclamation-triangle-fill" class="me-1"></i-bs><span i18n>Unavailable</span>
</span>
}
</div>
@@ -151,6 +151,23 @@ describe('DocumentLinkComponent', () => {
expect(component.selectedDocuments).toEqual([])
})
it('should preserve and neutrally label unavailable document IDs', async () => {
jest.spyOn(documentService, 'getFew').mockReturnValue(
of({
count: 0,
all: [],
results: [],
})
)
component.writeValue([99])
await fixture.whenStable()
expect(component.selectedDocuments).toEqual([{ id: 99 }])
expect(fixture.nativeElement.textContent).toContain('Unavailable')
expect(fixture.nativeElement.textContent).not.toContain('Not found')
})
it('should support unselect', () => {
const getSpy = jest.spyOn(documentService, 'getFew')
getSpy.mockImplementation((ids) => {
@@ -167,6 +184,15 @@ describe('DocumentLinkComponent', () => {
expect(component.selectedDocuments).toEqual([documents[1]])
})
it('should not unselect documents when disabled', () => {
component.disabled = true
component.selectedDocuments = [documents[0]]
component.unselect(documents[0])
expect(component.selectedDocuments).toEqual([documents[0]])
})
it('should use correct compare, trackBy functions', () => {
expect(component.compareDocuments(documents[0], { id: 1 })).toBeTruthy()
expect(component.compareDocuments(documents[0], { id: 2 })).toBeFalsy()
@@ -101,7 +101,7 @@ export class DocumentLinkComponent
.subscribe((documentResults) => {
this.loading.set(false)
this.selectedDocuments = documentIDs.map(
(id) => documentResults.results.find((d) => d.id === id) ?? {}
(id) => documentResults.results.find((d) => d.id === id) ?? { id }
)
super.writeValue(documentIDs)
})
@@ -142,6 +142,8 @@ export class DocumentLinkComponent
}
unselect(document: Document): void {
if (this.disabled) return
this.selectedDocuments = this.selectedDocuments.filter(
(d) => d && d.id !== document.id
)
@@ -114,13 +114,23 @@
</div>
</button>
<div ngbDropdownMenu aria-labelledby="dropdownSend" class="shadow">
<button ngbDropdownItem (click)="createShareLinkBundle()" [disabled]="!canSendSelection">
<i-bs name="link" class="me-1"></i-bs><ng-container i18n>Create a share link bundle</ng-container>
</button>
<button ngbDropdownItem (click)="manageShareLinkBundles()">
<i-bs name="list-ul" class="me-1"></i-bs><ng-container i18n>Manage share link bundles</ng-container>
</button>
<div class="dropdown-divider"></div>
@if (permissionService.currentUserCan(PermissionAction.Add, PermissionType.ShareLinkBundle)) {
<button ngbDropdownItem (click)="createShareLinkBundle()" [disabled]="!canSendSelection">
<i-bs name="link" class="me-1"></i-bs><ng-container i18n>Create a share link bundle</ng-container>
</button>
}
@if (permissionService.currentUserCan(PermissionAction.View, PermissionType.ShareLinkBundle)) {
<button ngbDropdownItem (click)="manageShareLinkBundles()">
<i-bs name="list-ul" class="me-1"></i-bs><ng-container i18n>Manage share link bundles</ng-container>
</button>
}
@if (
emailEnabled &&
(permissionService.currentUserCan(PermissionAction.Add, PermissionType.ShareLinkBundle) ||
permissionService.currentUserCan(PermissionAction.View, PermissionType.ShareLinkBundle))
) {
<div class="dropdown-divider"></div>
}
@if (emailEnabled) {
<button ngbDropdownItem (click)="emailSelected()" [disabled]="!canSendSelection">
<i-bs name="envelope" class="me-1"></i-bs><ng-container i18n>Email</ng-container>
@@ -19,7 +19,11 @@ import { StoragePath } from 'src/app/data/storage-path'
import { Tag } from 'src/app/data/tag'
import { FilterPipe } from 'src/app/pipes/filter.pipe'
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { PermissionsService } from 'src/app/services/permissions.service'
import {
PermissionAction,
PermissionsService,
PermissionType,
} from 'src/app/services/permissions.service'
import { CorrespondentService } from 'src/app/services/rest/correspondent.service'
import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service'
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
@@ -252,6 +256,54 @@ describe('BulkEditorComponent', () => {
).toBe(true)
})
it('should only show permitted share link bundle actions', () => {
permissionsService.initialize(
[
permissionsService.getPermissionCode(
PermissionAction.Add,
PermissionType.ShareLinkBundle
),
],
{ is_superuser: false } as any
)
fixture.detectChanges()
expect(fixture.nativeElement.textContent).toContain(
'Create a share link bundle'
)
expect(fixture.nativeElement.textContent).not.toContain(
'Manage share link bundles'
)
permissionsService.initialize(
[
permissionsService.getPermissionCode(
PermissionAction.View,
PermissionType.ShareLinkBundle
),
],
{ is_superuser: false } as any
)
fixture.detectChanges()
expect(fixture.nativeElement.textContent).not.toContain(
'Create a share link bundle'
)
expect(fixture.nativeElement.textContent).toContain(
'Manage share link bundles'
)
permissionsService.initialize([], { is_superuser: false } as any)
fixture.detectChanges()
expect(fixture.nativeElement.textContent).not.toContain(
'Create a share link bundle'
)
expect(fixture.nativeElement.textContent).not.toContain(
'Manage share link bundles'
)
})
it('should apply selection data to correspondents menu', () => {
jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
fixture.detectChanges()
@@ -101,7 +101,7 @@ export class BulkEditorComponent
private toastService = inject(ToastService)
private storagePathService = inject(StoragePathService)
private customFieldService = inject(CustomFieldsService)
private permissionService = inject(PermissionsService)
public readonly permissionService = inject(PermissionsService)
private savedViewService = inject(SavedViewService)
private readonly shareLinkBundleService = inject(ShareLinkBundleService)
+30
View File
@@ -93,6 +93,36 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase):
self.assertEqual(response.data["count"], 0)
self.assertEqual(len(results), 0)
def test_search_after_restore_from_trash(self) -> None:
"""
GIVEN:
- Indexed document that was moved to the trash
WHEN:
- The document is restored from the trash
THEN:
- The document is searchable again without a reindex
"""
doc = Document.objects.create(
title="invoice",
content="the thing i bought at a shop and paid with bank account",
checksum="A",
pk=1,
)
get_backend().add_or_update(doc)
self.assertEqual(self.client.get("/api/documents/?query=shop").data["count"], 1)
self.client.delete(f"/api/documents/{doc.pk}/")
self.assertEqual(self.client.get("/api/documents/?query=shop").data["count"], 0)
response = self.client.post(
"/api/trash/",
{"action": "restore", "documents": [doc.pk]},
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(self.client.get("/api/documents/?query=shop").data["count"], 1)
def test_simple_text_search(self) -> None:
tagged = Tag.objects.create(name="invoice")
matching_doc = Document.objects.create(
+8 -1
View File
@@ -5432,8 +5432,15 @@ class TrashView(ListModelMixin, PassUserMixin):
return HttpResponseForbidden("Insufficient permissions")
action = serializer.validated_data.get("action")
if action == "restore":
for doc in Document.deleted_objects.filter(id__in=doc_ids).all():
restored = list(Document.deleted_objects.filter(id__in=doc_ids))
for doc in restored:
doc.restore(strict=False)
if restored:
from documents.search import get_backend
with get_backend().batch_update() as batch:
for doc in restored:
batch.add_or_update(doc)
elif action == "empty":
if doc_ids is None:
doc_ids = [doc.id for doc in docs]