mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Refactor document edit permission check
This commit is contained in:
		| @@ -344,7 +344,7 @@ export class DocumentDetailComponent | |||||||
|  |  | ||||||
|   private prepareForm(doc: Document): void { |   private prepareForm(doc: Document): void { | ||||||
|     this.documentForm.reset(this.mapDocToForm(doc), { emitEvent: false }) |     this.documentForm.reset(this.mapDocToForm(doc), { emitEvent: false }) | ||||||
|     if (!this.userCanEdit) { |     if (!this.userCanEditDoc(doc)) { | ||||||
|       this.documentForm.disable({ emitEvent: false }) |       this.documentForm.disable({ emitEvent: false }) | ||||||
|     } else { |     } else { | ||||||
|       this.documentForm.enable({ emitEvent: false }) |       this.documentForm.enable({ emitEvent: false }) | ||||||
| @@ -1215,16 +1215,19 @@ export class DocumentDetailComponent | |||||||
|     ) { |     ) { | ||||||
|       doc.owner = this.store.value.permissions_form.owner |       doc.owner = this.store.value.permissions_form.owner | ||||||
|     } |     } | ||||||
|  |     return !this.document || this.userCanEditDoc(doc) | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   private userCanEditDoc(doc: Document): boolean { | ||||||
|     return ( |     return ( | ||||||
|       !this.document || |       this.permissionsService.currentUserCan( | ||||||
|       (this.permissionsService.currentUserCan( |  | ||||||
|         PermissionAction.Change, |         PermissionAction.Change, | ||||||
|         PermissionType.Document |         PermissionType.Document | ||||||
|       ) && |       ) && | ||||||
|       this.permissionsService.currentUserHasObjectPermissions( |       this.permissionsService.currentUserHasObjectPermissions( | ||||||
|         PermissionAction.Change, |         PermissionAction.Change, | ||||||
|         doc |         doc | ||||||
|         )) |       ) | ||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 shamoon
					shamoon