Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix: correct sharelink bundle + document link permissions display bugs (#13827)

shamoone1aa9997d764
diff --git a/src-ui/src/app/components/common/input/document-link/document-link.component.html b/src-ui/src/app/components/common/input/document-link/document-link.component.html
index 01df7c324..f60420791 100644
--- a/src-ui/src/app/components/common/input/document-link/document-link.component.html
+++ b/src-ui/src/app/components/common/input/document-link/document-link.component.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>
diff --git a/src-ui/src/app/components/common/input/document-link/document-link.component.spec.ts b/src-ui/src/app/components/common/input/document-link/document-link.component.spec.ts
index f872cb4b9..be479f2a4 100644
--- a/src-ui/src/app/components/common/input/document-link/document-link.component.spec.ts
+++ b/src-ui/src/app/components/common/input/document-link/document-link.component.spec.ts
@@ -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()
diff --git a/src-ui/src/app/components/common/input/document-link/document-link.component.ts b/src-ui/src/app/components/common/input/document-link/document-link.component.ts
index cc6b8a6a7..4209bb9d0 100644
--- a/src-ui/src/app/components/common/input/document-link/document-link.component.ts
+++ b/src-ui/src/app/components/common/input/document-link/document-link.component.ts
@@ -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
)
diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html
index 94c4dba9a..df9d5c299 100644
--- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html
+++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.html
@@ -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>
diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts
index a8d99b656..b8696a958 100644
--- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts
+++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.spec.ts
@@ -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()
diff --git a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts
index 3145e3959..fb7c20776 100644
--- a/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts
+++ b/src-ui/src/app/components/document-list/bulk-editor/bulk-editor.component.ts
@@ -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)