mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-24 01:06:17 +00: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