]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Consider user permissions 28555/head
authorTatjana Dehler <tdehler@suse.com>
Wed, 3 Apr 2019 14:24:11 +0000 (16:24 +0200)
committerTatjana Dehler <tdehler@suse.com>
Fri, 14 Jun 2019 13:53:44 +0000 (15:53 +0200)
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 aa68aca006bc084e6300b55123b82d780e428405)

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-flags-modal/osd-flags-modal.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-flags-modal/osd-flags-modal.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-pg-scrub-modal/osd-pg-scrub-modal.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-pg-scrub-modal/osd-pg-scrub-modal.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-recv-speed-modal/osd-recv-speed-modal.component.ts

index 59e2388593fa7e50e3b8b30ecb387bc85c1bdc18..13ed7dfea77962f5059db38958d0c5db97bd8e97 100644 (file)
@@ -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"
index 92985516a001ca48a5882f84ddbe487a81a4f593..60b374c0070dc95bec4f234bfba432968a458eb6 100644 (file)
@@ -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({
@@ -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 = {
@@ -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[]) => {
index f7646bc024e00ae62af0622172ca2c2c59fa3fdd..54182338efd8554a01e5a5034ae620b62df2e4b6 100644 (file)
         </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()">
index 66059f117145f0ecc3ca8633a5c416ab34f2b020..57fb35851865ee2d1ec67f45848093b76eeac1d2 100644 (file)
@@ -46,7 +46,7 @@ export class OsdListComponent implements OnInit {
   tableActions: CdTableAction[];
   bsModalRef: BsModalRef;
   columns: CdTableColumn[];
-  generalTableActions: any[];
+  advancedTableActions: any[];
 
   osds = [];
   selection = new CdTableSelection();
@@ -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
       }
     ];
   }
@@ -189,6 +197,8 @@ export class OsdListComponent implements OnInit {
         cellTransformation: CellTemplate.perSecond
       }
     ];
+
+    this.removeActionsWithNoPermissions();
   }
 
   get hasOsdSelected() {
@@ -259,7 +269,7 @@ export class OsdListComponent implements OnInit {
     this.bsModalRef = this.modalService.show(OsdScrubModalComponent, { initialState });
   }
 
-  configureClusterAction() {
+  configureFlagsAction() {
     this.bsModalRef = this.modalService.show(OsdFlagsModalComponent, {});
   }
 
@@ -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);
+  }
 }
index e3ee72126f3101972d86728e9df32d71d954c9c8..9f447db83415bd8cafcb6dae21d419f8847a8d9a 100644 (file)
@@ -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>
index 2b17dba5bde1d7305005e47415ba8a59cd346af5..b21136beba357f16a6c0bdf93f9447000a1a6158 100644 (file)
@@ -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';
 
@@ -20,6 +22,7 @@ export class OsdPgScrubModalComponent {
   osdPgScrubForm: CdFormGroup;
   action: string;
   resource: string;
+  permissions: Permissions;
 
   @ViewChild('basicOptionsValues')
   basicOptionsValues: ConfigOptionComponent;
@@ -33,6 +36,7 @@ export class OsdPgScrubModalComponent {
 
   constructor(
     public bsModalRef: BsModalRef,
+    private authStorageService: AuthStorageService,
     private notificationService: NotificationService,
     private i18n: I18n,
     public actionLabels: ActionLabelsI18n
@@ -40,6 +44,7 @@ export class OsdPgScrubModalComponent {
     this.osdPgScrubForm = new CdFormGroup({});
     this.resource = this.i18n('PG scrub options');
     this.action = this.actionLabels.EDIT;
+    this.permissions = this.authStorageService.getPermissions();
   }
 
   submitAction() {
index fb18166890ff186b16311c46304c4a9c514dbd91..c06d1b99684fab48a5c3e1da20ef13640b0933af 100755 (executable)
@@ -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"
index d4a253c54fe51c877257d0eafa54cd8fd5b201bc..d98ea39a855392f225c5f6037ded1fff821830ac 100755 (executable)
@@ -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({
@@ -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] }),