Disable action buttons if user have perms

This commit is contained in:
shamoon 2024-04-02 23:25:28 -07:00
parent 0460e12b74
commit 6447d0820f
3 changed files with 33 additions and 4 deletions

View File

@ -35,6 +35,7 @@ import {
} from '@angular/cdk/drag-drop' } from '@angular/cdk/drag-drop'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { ProfileEditDialogComponent } from '../common/profile-edit-dialog/profile-edit-dialog.component' import { ProfileEditDialogComponent } from '../common/profile-edit-dialog/profile-edit-dialog.component'
import { ObjectWithId } from 'src/app/data/object-with-id'
@Component({ @Component({
selector: 'pngx-app-frame', selector: 'pngx-app-frame',

View File

@ -28,6 +28,7 @@
<div class="btn-group ms-auto"> <div class="btn-group ms-auto">
<button #primaryButton type="button" class="btn btn-sm btn-outline-primary d-flex" <button #primaryButton type="button" class="btn btn-sm btn-outline-primary d-flex"
(click)="primaryAction(type, item); $event.stopPropagation()" (click)="primaryAction(type, item); $event.stopPropagation()"
[disabled]="disablePrimaryButton(type, item)"
(mouseenter)="onButtonHover($event)"> (mouseenter)="onButtonHover($event)">
@if (type === 'document') { @if (type === 'document') {
<i-bs width="1em" height="1em" name="pencil"></i-bs> <i-bs width="1em" height="1em" name="pencil"></i-bs>
@ -43,6 +44,7 @@
@if (type !== 'workflow' && type !== 'customField' && type !== 'group' && type !== 'user') { @if (type !== 'workflow' && type !== 'customField' && type !== 'group' && type !== 'user') {
<button #secondaryButton type="button" class="btn btn-sm btn-outline-primary d-flex" <button #secondaryButton type="button" class="btn btn-sm btn-outline-primary d-flex"
(click)="secondaryAction(type, item); $event.stopPropagation()" (click)="secondaryAction(type, item); $event.stopPropagation()"
[disabled]="disableSecondaryButton(type, item)"
(mouseenter)="onButtonHover($event)"> (mouseenter)="onButtonHover($event)">
@if (type === 'document') { @if (type === 'document') {
<i-bs width="1em" height="1em" name="download"></i-bs> <i-bs width="1em" height="1em" name="download"></i-bs>
@ -57,7 +59,7 @@
</div> </div>
</ng-template> </ng-template>
<div ngbDropdownMenu class="w-100 mh-75 overflow-y-scroll shadow-lgs"> <div ngbDropdownMenu class="w-100 mh-75 overflow-y-scroll shadow-lg">
@if (searchResults?.total === 0) { @if (searchResults?.total === 0) {
<h6 class="dropdown-header" i18n="@@searchResults.noResults">No results</h6> <h6 class="dropdown-header" i18n="@@searchResults.noResults">No results</h6>
} @else { } @else {

View File

@ -1,5 +1,4 @@
import { import {
AfterViewInit,
Component, Component,
ElementRef, ElementRef,
HostListener, HostListener,
@ -34,6 +33,10 @@ import {
FILTER_HAS_DOCUMENT_TYPE_ANY, FILTER_HAS_DOCUMENT_TYPE_ANY,
FILTER_HAS_STORAGE_PATH_ANY, FILTER_HAS_STORAGE_PATH_ANY,
} from 'src/app/data/filter-rule-type' } from 'src/app/data/filter-rule-type'
import {
PermissionAction,
PermissionsService,
} from 'src/app/services/permissions.service'
@Component({ @Component({
selector: 'pngx-global-search', selector: 'pngx-global-search',
@ -81,7 +84,7 @@ export class GlobalSearchComponent {
this.currentItemIndex = -1 this.currentItemIndex = -1
} }
} else if (event.key === 'ArrowRight') { } else if (event.key === 'ArrowRight') {
this.secondaryButtons.get(this.domIndex).nativeElement.focus() this.secondaryButtons.get(this.domIndex)?.nativeElement.focus()
} else if (event.key === 'ArrowLeft') { } else if (event.key === 'ArrowLeft') {
this.primaryButtons.get(this.domIndex).nativeElement.focus() this.primaryButtons.get(this.domIndex).nativeElement.focus()
} }
@ -93,7 +96,8 @@ export class GlobalSearchComponent {
private router: Router, private router: Router,
private modalService: NgbModal, private modalService: NgbModal,
private documentService: DocumentService, private documentService: DocumentService,
private documentListViewService: DocumentListViewService private documentListViewService: DocumentListViewService,
private permissionsService: PermissionsService
) { ) {
this.queryDebounce = new Subject<string>() this.queryDebounce = new Subject<string>()
@ -268,4 +272,26 @@ export class GlobalSearchComponent {
this.reset() this.reset()
} }
} }
public disablePrimaryButton(type: string, object: ObjectWithId): boolean {
if (['workflow', 'customField', 'group', 'user'].includes(type)) {
return !this.permissionsService.currentUserHasObjectPermissions(
PermissionAction.Change,
object
)
}
return false
}
public disableSecondaryButton(type: string, object: ObjectWithId): boolean {
if ('document' === type) {
return false
}
return !this.permissionsService.currentUserHasObjectPermissions(
PermissionAction.Change,
object
)
}
} }