mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Fix: bulk edit objects does not respect global permissions (#5888)
This commit is contained in:
		| @@ -2,10 +2,10 @@ | ||||
|   <button class="btn btn-sm btn-outline-secondary me-2" (click)="clearSelection()" [hidden]="selectedObjects.size === 0"> | ||||
|     <i-bs  name="x"></i-bs> <ng-container i18n>Clear selection</ng-container> | ||||
|     </button> | ||||
|     <button type="button" class="btn btn-sm btn-outline-primary me-2" (click)="setPermissions()" [disabled]="!userOwnsAll || selectedObjects.size === 0"> | ||||
|     <button type="button" class="btn btn-sm btn-outline-primary me-2" (click)="setPermissions()" [disabled]="!userCanBulkEdit(PermissionAction.Change) || selectedObjects.size === 0"> | ||||
|       <i-bs name="person-fill-lock"></i-bs> <ng-container i18n>Permissions</ng-container> | ||||
|     </button> | ||||
|     <button type="button" class="btn btn-sm btn-outline-danger me-5" (click)="delete()" [disabled]="!userOwnsAll || selectedObjects.size === 0"> | ||||
|     <button type="button" class="btn btn-sm btn-outline-danger me-5" (click)="delete()" [disabled]="!userCanBulkEdit(PermissionAction.Delete) || selectedObjects.size === 0"> | ||||
|       <i-bs name="trash"></i-bs> <ng-container i18n>Delete</ng-container> | ||||
|     </button> | ||||
|     <button type="button" class="btn btn-sm btn-outline-primary" (click)="openCreateDialog()" *pngxIfPermissions="{ action: PermissionAction.Add, type: permissionType }"> | ||||
|   | ||||
| @@ -23,7 +23,10 @@ import { TagService } from 'src/app/services/rest/tag.service' | ||||
| import { PageHeaderComponent } from '../../common/page-header/page-header.component' | ||||
| import { TagListComponent } from '../tag-list/tag-list.component' | ||||
| import { ManagementListComponent } from './management-list.component' | ||||
| import { PermissionsService } from 'src/app/services/permissions.service' | ||||
| import { | ||||
|   PermissionAction, | ||||
|   PermissionsService, | ||||
| } from 'src/app/services/permissions.service' | ||||
| import { ToastService } from 'src/app/services/toast.service' | ||||
| import { EditDialogComponent } from '../../common/edit-dialog/edit-dialog.component' | ||||
| import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component' | ||||
| @@ -65,6 +68,7 @@ describe('ManagementListComponent', () => { | ||||
|   let modalService: NgbModal | ||||
|   let toastService: ToastService | ||||
|   let documentListViewService: DocumentListViewService | ||||
|   let permissionsService: PermissionsService | ||||
|  | ||||
|   beforeEach(async () => { | ||||
|     TestBed.configureTestingModule({ | ||||
| @@ -77,18 +81,7 @@ describe('ManagementListComponent', () => { | ||||
|         ConfirmDialogComponent, | ||||
|         PermissionsDialogComponent, | ||||
|       ], | ||||
|       providers: [ | ||||
|         { | ||||
|           provide: PermissionsService, | ||||
|           useValue: { | ||||
|             currentUserCan: () => true, | ||||
|             currentUserHasObjectPermissions: () => true, | ||||
|             currentUserOwnsObject: () => true, | ||||
|           }, | ||||
|         }, | ||||
|         DatePipe, | ||||
|         PermissionsGuard, | ||||
|       ], | ||||
|       providers: [DatePipe, PermissionsGuard], | ||||
|       imports: [ | ||||
|         HttpClientTestingModule, | ||||
|         NgbPaginationModule, | ||||
| @@ -115,6 +108,14 @@ describe('ManagementListComponent', () => { | ||||
|           }) | ||||
|         } | ||||
|       ) | ||||
|     permissionsService = TestBed.inject(PermissionsService) | ||||
|     jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true) | ||||
|     jest | ||||
|       .spyOn(permissionsService, 'currentUserHasObjectPermissions') | ||||
|       .mockReturnValue(true) | ||||
|     jest | ||||
|       .spyOn(permissionsService, 'currentUserOwnsObject') | ||||
|       .mockReturnValue(true) | ||||
|     modalService = TestBed.inject(NgbModal) | ||||
|     toastService = TestBed.inject(ToastService) | ||||
|     documentListViewService = TestBed.inject(DocumentListViewService) | ||||
| @@ -312,4 +313,10 @@ describe('ManagementListComponent', () => { | ||||
|     expect(bulkEditSpy).toHaveBeenCalled() | ||||
|     expect(successToastSpy).toHaveBeenCalled() | ||||
|   }) | ||||
|  | ||||
|   it('should disallow bulk permissions or delete objects if no global perms', () => { | ||||
|     jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(false) | ||||
|     expect(component.userCanBulkEdit(PermissionAction.Delete)).toBeFalsy() | ||||
|     expect(component.userCanBulkEdit(PermissionAction.Change)).toBeFalsy() | ||||
|   }) | ||||
| }) | ||||
|   | ||||
| @@ -15,16 +15,14 @@ import { | ||||
|   MATCH_NONE, | ||||
| } from 'src/app/data/matching-model' | ||||
| import { ObjectWithId } from 'src/app/data/object-with-id' | ||||
| import { | ||||
|   ObjectWithPermissions, | ||||
|   PermissionsObject, | ||||
| } from 'src/app/data/object-with-permissions' | ||||
| import { ObjectWithPermissions } from 'src/app/data/object-with-permissions' | ||||
| import { | ||||
|   SortableDirective, | ||||
|   SortEvent, | ||||
| } from 'src/app/directives/sortable.directive' | ||||
| import { DocumentListViewService } from 'src/app/services/document-list-view.service' | ||||
| import { | ||||
|   PermissionAction, | ||||
|   PermissionsService, | ||||
|   PermissionType, | ||||
| } from 'src/app/services/permissions.service' | ||||
| @@ -250,7 +248,9 @@ export abstract class ManagementListComponent<T extends ObjectWithId> | ||||
|     ) | ||||
|   } | ||||
|  | ||||
|   get userOwnsAll(): boolean { | ||||
|   userCanBulkEdit(action: PermissionAction): boolean { | ||||
|     if (!this.permissionsService.currentUserCan(action, this.permissionType)) | ||||
|       return false | ||||
|     let ownsAll: boolean = true | ||||
|     const objects = this.data.filter((o) => this.selectedObjects.has(o.id)) | ||||
|     ownsAll = objects.every((o) => | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 shamoon
					shamoon