Skip to content

Commit

Permalink
mgr/dashboard: Consider user permissions
Browse files Browse the repository at this point in the history
Consider user permissions when showing advanced table actions and hide
all buttons requiring missing permissions from the user.
Also consider user permissions when showing submit buttons.

Signed-off-by: Tatjana Dehler <tdehler@suse.com>
(cherry picked from commit aa68aca)
  • Loading branch information
Tatjana Dehler committed Jun 14, 2019
1 parent e78c7a4 commit 7384e4c
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 19 deletions.
Expand Up @@ -29,7 +29,8 @@

<div class="modal-footer">
<div class="button-group text-right">
<cd-submit-button (submitAction)="submitAction()"
<cd-submit-button *ngIf="permissions.osd.update"
(submitAction)="submitAction()"
[form]="osdFlagsForm"
i18n>Submit</cd-submit-button>
<cd-back-button [back]="bsModalRef.hide"
Expand Down
Expand Up @@ -7,6 +7,8 @@ import { BsModalRef } from 'ngx-bootstrap/modal';

import { OsdService } from '../../../../shared/api/osd.service';
import { NotificationType } from '../../../../shared/enum/notification-type.enum';
import { Permissions } from '../../../../shared/models/permissions';
import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
import { NotificationService } from '../../../../shared/services/notification.service';

@Component({
Expand All @@ -15,6 +17,8 @@ import { NotificationService } from '../../../../shared/services/notification.se
styleUrls: ['./osd-flags-modal.component.scss']
})
export class OsdFlagsModalComponent implements OnInit {
permissions: Permissions;

osdFlagsForm = new FormGroup({});

allFlags = {
Expand Down Expand Up @@ -112,10 +116,13 @@ export class OsdFlagsModalComponent implements OnInit {

constructor(
public bsModalRef: BsModalRef,
private authStorageService: AuthStorageService,
private osdService: OsdService,
private notificationService: NotificationService,
private i18n: I18n
) {}
) {
this.permissions = this.authStorageService.getPermissions();
}

ngOnInit() {
this.osdService.getFlags().subscribe((res: string[]) => {
Expand Down
Expand Up @@ -15,24 +15,23 @@
</cd-table-actions>

<div class="btn-group"
dropdown>
dropdown
*ngIf="advancedTableActions.length > 0">
<button type="button"
class="btn btn-sm btn-default btn-label tc_configureCluster"
(click)="configureClusterAction()">
<i class="fa fa-fw fa-cog"
aria-hidden="true">
</i>
<ng-container i18n>Set Cluster-wide Flags</ng-container>
(click)="advancedTableActions[0].click()">
<i class="fa fa-fw {{ advancedTableActions[0].icon }}"></i><span>{{ advancedTableActions[0].name }}</span>
</button>
<button type="button"
dropdownToggle
class="btn btn-sm btn-default dropdown-toggle dropdown-toggle-split">
class="btn btn-sm btn-default dropdown-toggle dropdown-toggle-split"
*ngIf="advancedTableActions.length > 1">
<span class="caret caret-black"></span>
</button>
<ul *dropdownMenu
class="dropdown-menu"
role="menu">
<ng-container *ngFor="let action of generalTableActions">
<ng-container *ngFor="let action of advancedTableActions | slice:1">
<li role="menuitem">
<a class="dropdown-item"
(click)="action.click()">
Expand Down
Expand Up @@ -46,7 +46,7 @@ export class OsdListComponent implements OnInit {
tableActions: CdTableAction[];
bsModalRef: BsModalRef;
columns: CdTableColumn[];
generalTableActions: any[];
advancedTableActions: any[];

osds = [];
selection = new CdTableSelection();
Expand Down Expand Up @@ -146,16 +146,24 @@ export class OsdListComponent implements OnInit {
icon: 'fa-remove'
}
];
this.generalTableActions = [
this.advancedTableActions = [
{
name: this.i18n('Set Cluster-wide Recovery Priority'),
name: this.i18n('Cluster-wide Flags'),
icon: 'fa-flag',
click: () => this.configureFlagsAction(),
permission: this.permissions.osd.read
},
{
name: this.i18n('Cluster-wide Recovery Priority'),
icon: 'fa-cog',
click: () => this.configureQosParamsAction()
click: () => this.configureQosParamsAction(),
permission: this.permissions.configOpt.read
},
{
name: this.i18n('PG scrub configuration'),
name: this.i18n('PG scrub'),
icon: 'fa-stethoscope',
click: () => this.configurePgScrubAction()
click: () => this.configurePgScrubAction(),
permission: this.permissions.configOpt.read
}
];
}
Expand Down Expand Up @@ -189,6 +197,8 @@ export class OsdListComponent implements OnInit {
cellTransformation: CellTemplate.perSecond
}
];

this.removeActionsWithNoPermissions();
}

get hasOsdSelected() {
Expand Down Expand Up @@ -259,7 +269,7 @@ export class OsdListComponent implements OnInit {
this.bsModalRef = this.modalService.show(OsdScrubModalComponent, { initialState });
}

configureClusterAction() {
configureFlagsAction() {
this.bsModalRef = this.modalService.show(OsdFlagsModalComponent, {});
}

Expand Down Expand Up @@ -324,4 +334,16 @@ export class OsdListComponent implements OnInit {
configurePgScrubAction() {
this.bsModalRef = this.modalService.show(OsdPgScrubModalComponent, { class: 'modal-lg' });
}

/**
* Removes all actions from 'advancedTableActions' that need a permission the user doesn't have.
*/
private removeActionsWithNoPermissions() {
if (!this.permissions) {
this.advancedTableActions = [];
return;
}

this.advancedTableActions = this.advancedTableActions.filter((action) => action.permission);
}
}
Expand Up @@ -35,7 +35,8 @@
</div>
<div class="modal-footer">
<div class="button-group text-right">
<cd-submit-button (submitAction)="submitAction()"
<cd-submit-button *ngIf="permissions.configOpt.update"
(submitAction)="submitAction()"
[form]="osdPgScrubForm"
i18n="form action button|Example: Create Pool@@formActionButton"
type="button">{{ action | titlecase }} {{ resource | upperFirst }}</cd-submit-button>
Expand Down
Expand Up @@ -8,6 +8,8 @@ import { ConfigOptionComponent } from '../../../../shared/components/config-opti
import { ActionLabelsI18n } from '../../../../shared/constants/app.constants';
import { NotificationType } from '../../../../shared/enum/notification-type.enum';
import { CdFormGroup } from '../../../../shared/forms/cd-form-group';
import { Permissions } from '../../../../shared/models/permissions';
import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
import { NotificationService } from '../../../../shared/services/notification.service';
import { OsdPgScrubModalOptions } from './osd-pg-scrub-modal.options';

Expand All @@ -20,6 +22,7 @@ export class OsdPgScrubModalComponent {
osdPgScrubForm: CdFormGroup;
action: string;
resource: string;
permissions: Permissions;

@ViewChild('basicOptionsValues')
basicOptionsValues: ConfigOptionComponent;
Expand All @@ -33,13 +36,15 @@ export class OsdPgScrubModalComponent {

constructor(
public bsModalRef: BsModalRef,
private authStorageService: AuthStorageService,
private notificationService: NotificationService,
private i18n: I18n,
public actionLabels: ActionLabelsI18n
) {
this.osdPgScrubForm = new CdFormGroup({});
this.resource = this.i18n('PG scrub options');
this.action = this.actionLabels.EDIT;
this.permissions = this.authStorageService.getPermissions();
}

submitAction() {
Expand Down
Expand Up @@ -82,7 +82,8 @@
</div>
<div class="modal-footer">
<div class="button-group text-right">
<cd-submit-button (submitAction)="submitAction()"
<cd-submit-button *ngIf="permissions.configOpt.update"
(submitAction)="submitAction()"
[form]="osdRecvSpeedForm"
i18n>Submit</cd-submit-button>
<cd-back-button [back]="bsModalRef.hide"
Expand Down
Expand Up @@ -10,6 +10,8 @@ import { OsdService } from '../../../../shared/api/osd.service';
import { ConfigOptionTypes } from '../../../../shared/components/config-option/config-option.types';
import { NotificationType } from '../../../../shared/enum/notification-type.enum';
import { CdFormGroup } from '../../../../shared/forms/cd-form-group';
import { Permissions } from '../../../../shared/models/permissions';
import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
import { NotificationService } from '../../../../shared/services/notification.service';

@Component({
Expand All @@ -19,16 +21,20 @@ import { NotificationService } from '../../../../shared/services/notification.se
})
export class OsdRecvSpeedModalComponent implements OnInit {
osdRecvSpeedForm: CdFormGroup;
permissions: Permissions;

priorities = [];
priorityAttrs = {};

constructor(
public bsModalRef: BsModalRef,
private authStorageService: AuthStorageService,
private configService: ConfigurationService,
private notificationService: NotificationService,
private i18n: I18n,
private osdService: OsdService
) {
this.permissions = this.authStorageService.getPermissions();
this.priorities = this.osdService.osdRecvSpeedModalPriorities.KNOWN_PRIORITIES;
this.osdRecvSpeedForm = new CdFormGroup({
priority: new FormControl(null, { validators: [Validators.required] }),
Expand Down

0 comments on commit 7384e4c

Please sign in to comment.