mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Management lists edit / delete button disabling by permissions
This commit is contained in:
		| @@ -4,7 +4,10 @@ import { FILTER_CORRESPONDENT } from 'src/app/data/filter-rule-type' | ||||
| import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent' | ||||
| import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe' | ||||
| import { DocumentListViewService } from 'src/app/services/document-list-view.service' | ||||
| import { PermissionType } from 'src/app/services/permissions.service' | ||||
| import { | ||||
|   PermissionsService, | ||||
|   PermissionType, | ||||
| } from 'src/app/services/permissions.service' | ||||
| import { CorrespondentService } from 'src/app/services/rest/correspondent.service' | ||||
| import { ToastService } from 'src/app/services/toast.service' | ||||
| import { CorrespondentEditDialogComponent } from '../../common/edit-dialog/correspondent-edit-dialog/correspondent-edit-dialog.component' | ||||
| @@ -22,6 +25,7 @@ export class CorrespondentListComponent extends ManagementListComponent<Paperles | ||||
|     modalService: NgbModal, | ||||
|     toastService: ToastService, | ||||
|     documentListViewService: DocumentListViewService, | ||||
|     permissionsService: PermissionsService, | ||||
|     private datePipe: CustomDatePipe | ||||
|   ) { | ||||
|     super( | ||||
| @@ -30,6 +34,7 @@ export class CorrespondentListComponent extends ManagementListComponent<Paperles | ||||
|       CorrespondentEditDialogComponent, | ||||
|       toastService, | ||||
|       documentListViewService, | ||||
|       permissionsService, | ||||
|       FILTER_CORRESPONDENT, | ||||
|       $localize`correspondent`, | ||||
|       $localize`correspondents`, | ||||
|   | ||||
| @@ -3,7 +3,10 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||||
| import { FILTER_DOCUMENT_TYPE } from 'src/app/data/filter-rule-type' | ||||
| import { PaperlessDocumentType } from 'src/app/data/paperless-document-type' | ||||
| import { DocumentListViewService } from 'src/app/services/document-list-view.service' | ||||
| import { PermissionType } from 'src/app/services/permissions.service' | ||||
| import { | ||||
|   PermissionsService, | ||||
|   PermissionType, | ||||
| } from 'src/app/services/permissions.service' | ||||
| import { DocumentTypeService } from 'src/app/services/rest/document-type.service' | ||||
| import { ToastService } from 'src/app/services/toast.service' | ||||
| import { DocumentTypeEditDialogComponent } from '../../common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component' | ||||
| @@ -19,7 +22,8 @@ export class DocumentTypeListComponent extends ManagementListComponent<Paperless | ||||
|     documentTypeService: DocumentTypeService, | ||||
|     modalService: NgbModal, | ||||
|     toastService: ToastService, | ||||
|     documentListViewService: DocumentListViewService | ||||
|     documentListViewService: DocumentListViewService, | ||||
|     permissionsService: PermissionsService | ||||
|   ) { | ||||
|     super( | ||||
|       documentTypeService, | ||||
| @@ -27,6 +31,7 @@ export class DocumentTypeListComponent extends ManagementListComponent<Paperless | ||||
|       DocumentTypeEditDialogComponent, | ||||
|       toastService, | ||||
|       documentListViewService, | ||||
|       permissionsService, | ||||
|       FILTER_DOCUMENT_TYPE, | ||||
|       $localize`document type`, | ||||
|       $localize`document types`, | ||||
|   | ||||
| @@ -53,12 +53,12 @@ | ||||
|               <path fill-rule="evenodd" d="M1.5 1.5A.5.5 0 0 1 2 1h12a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-.128.334L10 8.692V13.5a.5.5 0 0 1-.342.474l-3 1A.5.5 0 0 1 6 14.5V8.692L1.628 3.834A.5.5 0 0 1 1.5 3.5v-2zm1 .5v1.308l4.372 4.858A.5.5 0 0 1 7 8.5v5.306l2-.666V8.5a.5.5 0 0 1 .128-.334L13.5 3.308V2h-11z"/> | ||||
|             </svg> <ng-container i18n>Documents</ng-container> | ||||
|           </button> | ||||
|           <button class="btn btn-sm btn-outline-secondary" (click)="openEditDialog(object)" *ifPermissions="{ action: PermissionAction.Change, type: permissionType }"> | ||||
|           <button class="btn btn-sm btn-outline-secondary" (click)="openEditDialog(object)" *ifPermissions="{ action: PermissionAction.Change, type: permissionType }" [disabled]="!userCanEdit(object)"> | ||||
|             <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-pencil" fill="currentColor" xmlns="http://www.w3.org/2000/svg"> | ||||
|               <path fill-rule="evenodd" d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5L13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175l-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"/> | ||||
|             </svg> <ng-container i18n>Edit</ng-container> | ||||
|           </button> | ||||
|           <button class="btn btn-sm btn-outline-danger" (click)="openDeleteDialog(object)" *ifPermissions="{ action: PermissionAction.Delete, type: permissionType }"> | ||||
|           <button class="btn btn-sm btn-outline-danger" (click)="openDeleteDialog(object)" *ifPermissions="{ action: PermissionAction.Delete, type: permissionType }" [disabled]="!userCanDelete(object)"> | ||||
|             <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16"> | ||||
|               <path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5zm3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0V6z"/> | ||||
|               <path fill-rule="evenodd" d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1v1zM4.118 4L4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4H4.118zM2.5 3V2h11v1h-11z"/> | ||||
|   | ||||
| @@ -14,12 +14,16 @@ import { | ||||
|   MATCH_AUTO, | ||||
| } from 'src/app/data/matching-model' | ||||
| import { ObjectWithId } from 'src/app/data/object-with-id' | ||||
| 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 { PermissionType } from 'src/app/services/permissions.service' | ||||
| import { | ||||
|   PermissionsService, | ||||
|   PermissionType, | ||||
| } from 'src/app/services/permissions.service' | ||||
| import { AbstractNameFilterService } from 'src/app/services/rest/abstract-name-filter-service' | ||||
| import { ToastService } from 'src/app/services/toast.service' | ||||
| import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component' | ||||
| @@ -46,6 +50,7 @@ export abstract class ManagementListComponent<T extends ObjectWithId> | ||||
|     private editDialogComponent: any, | ||||
|     private toastService: ToastService, | ||||
|     private documentListViewService: DocumentListViewService, | ||||
|     private permissionsService: PermissionsService, | ||||
|     protected filterRuleType: number, | ||||
|     public typeName: string, | ||||
|     public typeNamePlural: string, | ||||
| @@ -215,4 +220,17 @@ export abstract class ManagementListComponent<T extends ObjectWithId> | ||||
|   onNameFilterKeyUp(event: KeyboardEvent) { | ||||
|     if (event.code == 'Escape') this.nameFilterDebounce.next(null) | ||||
|   } | ||||
|  | ||||
|   userCanDelete(object: ObjectWithPermissions): boolean { | ||||
|     return ( | ||||
|       !object.owner || this.permissionsService.currentUserIsOwner(object.owner) | ||||
|     ) | ||||
|   } | ||||
|  | ||||
|   userCanEdit(object: ObjectWithPermissions): boolean { | ||||
|     return this.permissionsService.currentUserHasObjectPermissions( | ||||
|       this.PermissionAction.Change, | ||||
|       object | ||||
|     ) | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -3,7 +3,10 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||||
| import { FILTER_STORAGE_PATH } from 'src/app/data/filter-rule-type' | ||||
| import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path' | ||||
| import { DocumentListViewService } from 'src/app/services/document-list-view.service' | ||||
| import { PermissionType } from 'src/app/services/permissions.service' | ||||
| import { | ||||
|   PermissionsService, | ||||
|   PermissionType, | ||||
| } from 'src/app/services/permissions.service' | ||||
| import { StoragePathService } from 'src/app/services/rest/storage-path.service' | ||||
| import { ToastService } from 'src/app/services/toast.service' | ||||
| import { StoragePathEditDialogComponent } from '../../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component' | ||||
| @@ -19,7 +22,8 @@ export class StoragePathListComponent extends ManagementListComponent<PaperlessS | ||||
|     directoryService: StoragePathService, | ||||
|     modalService: NgbModal, | ||||
|     toastService: ToastService, | ||||
|     documentListViewService: DocumentListViewService | ||||
|     documentListViewService: DocumentListViewService, | ||||
|     permissionsService: PermissionsService | ||||
|   ) { | ||||
|     super( | ||||
|       directoryService, | ||||
| @@ -27,6 +31,7 @@ export class StoragePathListComponent extends ManagementListComponent<PaperlessS | ||||
|       StoragePathEditDialogComponent, | ||||
|       toastService, | ||||
|       documentListViewService, | ||||
|       permissionsService, | ||||
|       FILTER_STORAGE_PATH, | ||||
|       $localize`storage path`, | ||||
|       $localize`storage paths`, | ||||
|   | ||||
| @@ -3,7 +3,10 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||||
| import { FILTER_HAS_TAGS_ALL } from 'src/app/data/filter-rule-type' | ||||
| import { PaperlessTag } from 'src/app/data/paperless-tag' | ||||
| import { DocumentListViewService } from 'src/app/services/document-list-view.service' | ||||
| import { PermissionType } from 'src/app/services/permissions.service' | ||||
| import { | ||||
|   PermissionsService, | ||||
|   PermissionType, | ||||
| } from 'src/app/services/permissions.service' | ||||
| import { TagService } from 'src/app/services/rest/tag.service' | ||||
| import { ToastService } from 'src/app/services/toast.service' | ||||
| import { TagEditDialogComponent } from '../../common/edit-dialog/tag-edit-dialog/tag-edit-dialog.component' | ||||
| @@ -19,7 +22,8 @@ export class TagListComponent extends ManagementListComponent<PaperlessTag> { | ||||
|     tagService: TagService, | ||||
|     modalService: NgbModal, | ||||
|     toastService: ToastService, | ||||
|     documentListViewService: DocumentListViewService | ||||
|     documentListViewService: DocumentListViewService, | ||||
|     permissionsService: PermissionsService | ||||
|   ) { | ||||
|     super( | ||||
|       tagService, | ||||
| @@ -27,6 +31,7 @@ export class TagListComponent extends ManagementListComponent<PaperlessTag> { | ||||
|       TagEditDialogComponent, | ||||
|       toastService, | ||||
|       documentListViewService, | ||||
|       permissionsService, | ||||
|       FILTER_HAS_TAGS_ALL, | ||||
|       $localize`tag`, | ||||
|       $localize`tags`, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon