mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-28 13:37:32 +00:00
Fix: correct sharelink bundle + document link permissions display bugs (#13827)
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user