Bulk editor enabling/disabling by permissions

This commit is contained in:
Michael Shamoon
2022-12-08 02:22:58 -08:00
parent 42a5ac3936
commit a1c65256df
6 changed files with 39 additions and 8 deletions

View File

@@ -28,6 +28,7 @@
<app-filterable-dropdown class="me-2 me-md-3" title="Tags" icon="tag-fill" i18n-title
filterPlaceholder="Filter tags" i18n-filterPlaceholder
[items]="tags"
[disabled]="!userCanEditAll"
[editing]="true"
[multiple]="true"
[applyOnClose]="applyOnClose"
@@ -38,6 +39,7 @@
<app-filterable-dropdown class="me-2 me-md-3" title="Correspondent" icon="person-fill" i18n-title
filterPlaceholder="Filter correspondents" i18n-filterPlaceholder
[items]="correspondents"
[disabled]="!userCanEditAll"
[editing]="true"
[applyOnClose]="applyOnClose"
(open)="openCorrespondentDropdown()"
@@ -47,6 +49,7 @@
<app-filterable-dropdown class="me-2 me-md-3" title="Document type" icon="file-earmark-fill" i18n-title
filterPlaceholder="Filter document types" i18n-filterPlaceholder
[items]="documentTypes"
[disabled]="!userCanEditAll"
[editing]="true"
[applyOnClose]="applyOnClose"
(open)="openDocumentTypeDropdown()"
@@ -56,6 +59,7 @@
<app-filterable-dropdown class="me-2 me-md-3" title="Storage path" icon="folder-fill" i18n-title
filterPlaceholder="Filter storage paths" i18n-filterPlaceholder
[items]="storagePaths"
[disabled]="!userCanEditAll"
[editing]="true"
[applyOnClose]="applyOnClose"
(open)="openStoragePathDropdown()"
@@ -67,7 +71,7 @@
<div class="col-auto ms-auto mb-2 mb-xl-0 d-flex">
<div class="btn-toolbar me-2">
<button type="button" class="btn btn-sm btn-outline-primary me-2" (click)="setPermissions()">
<button type="button" class="btn btn-sm btn-outline-primary me-2" (click)="setPermissions()" [disabled]="!userOwnsAll">
<svg width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#person-fill-lock" />
</svg>&nbsp;<ng-container i18n>Permissions</ng-container>
@@ -93,11 +97,11 @@
<span class="visually-hidden">Preparing download...</span>
</div>
</button>
<button ngbDropdownItem (click)="redoOcrSelected()" i18n>Redo OCR</button>
<button ngbDropdownItem (click)="redoOcrSelected()" [disabled]="!userCanEditAll" i18n>Redo OCR</button>
</div>
</div>
<button type="button" class="btn btn-sm btn-outline-danger" (click)="applyDelete()" *ifPermissions="{ action: PermissionAction.Delete, type: PermissionType.Document }">
<button type="button" class="btn btn-sm btn-outline-danger" (click)="applyDelete()" *ifPermissions="{ action: PermissionAction.Delete, type: PermissionType.Document }" [disabled]="!userOwnsAll">
<svg width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#trash" />
</svg>&nbsp;<ng-container i18n>Delete</ng-container>

View File

@@ -27,6 +27,7 @@ import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path'
import { SETTINGS_KEYS } from 'src/app/data/paperless-uisettings'
import { ComponentWithPermissions } from '../../with-permissions/with-permissions.component'
import { PermissionsDialogComponent } from '../../common/permissions-dialog/permissions-dialog.component'
import { PermissionsService } from 'src/app/services/permissions.service'
@Component({
selector: 'app-bulk-editor',
@@ -55,7 +56,8 @@ export class BulkEditorComponent extends ComponentWithPermissions {
private openDocumentService: OpenDocumentsService,
private settings: SettingsService,
private toastService: ToastService,
private storagePathService: StoragePathService
private storagePathService: StoragePathService,
private permissionService: PermissionsService
) {
super()
}
@@ -67,6 +69,25 @@ export class BulkEditorComponent extends ComponentWithPermissions {
SETTINGS_KEYS.BULK_EDIT_CONFIRMATION_DIALOGS
)
get userCanEditAll(): boolean {
let canEdit: boolean = true
const docs = this.list.documents.filter((d) => this.list.selected.has(d.id))
canEdit = docs.every((d) =>
this.permissionService.currentUserHasObjectPermissions(
this.PermissionAction.Change,
d
)
)
return canEdit
}
get userOwnsAll(): boolean {
let ownsAll: boolean = true
const docs = this.list.documents.filter((d) => this.list.selected.has(d.id))
ownsAll = docs.every((d) => this.permissionService.currentUserOwnsObject(d))
return ownsAll
}
ngOnInit() {
this.tagService
.listAll()