]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: 'Logs' links permission in Landing Page 25231/head
authoralfonsomthd <almartin@redhat.com>
Mon, 3 Dec 2018 12:54:05 +0000 (13:54 +0100)
committeralfonsomthd <almartin@redhat.com>
Mon, 3 Dec 2018 12:54:05 +0000 (13:54 +0100)
- 'Logs' links in Landing Page cards' popovers
for cards 'Cluster Status' (when not in HEALTH_OK) and
'PG Status' appear only when the user has
the appropriate permissions.
- Some refactor.
- Added test: ensure that clickable text (popover) is shown
when there are health checks' messages.

Fixes: https://tracker.ceph.com/issues/37371
Signed-off-by: Alfonso Martínez <almartin@redhat.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts
src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf

index 54d9e40bd1551560ff1b23922bc4167b29bbc688..a5f9014bd75348832a9ab1b6f1c4ae587090d421 100644 (file)
@@ -19,8 +19,7 @@
                   *ngIf="healthData.health?.status">
       <ng-container *ngIf="healthData.health?.checks?.length > 0">
         <ng-template #healthChecks>
-          <p class="logs-link"
-             i18n>&rarr; See <a routerLink="/logs">Logs</a> for more details.</p>
+          <ng-container *ngTemplateOutlet="logsLink"></ng-container>
           <ul>
             <li *ngFor="let check of healthData.health.checks">
               <span [ngStyle]="check.severity | healthColor">{{ check.type }}</span>: {{ check.summary.message }}
@@ -39,7 +38,7 @@
           {{ healthData.health.status }}
         </div>
       </ng-container>
-      <ng-container *ngIf="healthData.health?.checks?.length == 0">
+      <ng-container *ngIf="!healthData.health?.checks?.length">
         <div [ngStyle]="healthData.health.status | healthColor">
           {{ healthData.health.status }}
         </div>
                     (click)="pgStatusTarget.toggle()"
                     *ngIf="healthData.pg_info">
         <ng-template #pgStatus>
-          <p class="logs-link"
-             i18n>&rarr; See <a routerLink="/logs">Logs</a> for more details.</p>
+          <ng-container *ngTemplateOutlet="logsLink"></ng-container>
           <ul>
             <li *ngFor="let pgStatesText of healthData.pg_info.statuses | keyvalue">
               {{ pgStatesText.key }}: {{ pgStatesText.value }}
       </cd-info-card>
     </div>
   </cd-info-group>
+
+  <ng-template #logsLink>
+    <ng-container *ngIf="permissions.log.read">
+      <p class="logs-link"
+         i18n><i class="fa fa-info-circle"></i> See <a routerLink="/logs">Logs</a> for more details.</p>
+    </ng-container>
+  </ng-template>
 </div>
index f4de0412581bcfc5c5c60fbfaa8772a7500704b4..847121617ae2e1905505ec78a0184bf8d572b47a 100644 (file)
@@ -1,6 +1,7 @@
 import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { NO_ERRORS_SCHEMA } from '@angular/core';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
 
 import * as _ from 'lodash';
 import { PopoverModule } from 'ngx-bootstrap/popover';
@@ -8,6 +9,8 @@ import { of } from 'rxjs';
 
 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
 import { HealthService } from '../../../shared/api/health.service';
+import { Permissions } from '../../../shared/models/permissions';
+import { AuthStorageService } from '../../../shared/services/auth-storage.service';
 import { SharedModule } from '../../../shared/shared.module';
 import { MdsSummaryPipe } from '../mds-summary.pipe';
 import { MgrSummaryPipe } from '../mgr-summary.pipe';
@@ -36,6 +39,11 @@ describe('HealthComponent', () => {
     df: { stats: { total_objects: 0 } },
     pg_info: {}
   };
+  const fakeAuthStorageService = {
+    getPermissions: () => {
+      return new Permissions({ log: ['read'] });
+    }
+  };
 
   configureTestBed({
     imports: [SharedModule, HttpClientTestingModule, PopoverModule.forRoot()],
@@ -49,7 +57,7 @@ describe('HealthComponent', () => {
       PgStatusPipe
     ],
     schemas: [NO_ERRORS_SCHEMA],
-    providers: i18nProviders
+    providers: [i18nProviders, { provide: AuthStorageService, useValue: fakeAuthStorageService }]
   });
 
   beforeEach(() => {
@@ -138,4 +146,35 @@ describe('HealthComponent', () => {
       expect(infoGroup.querySelectorAll('cd-info-card').length).toBe(1);
     });
   });
+
+  it('should render "Cluster Status" card text that is not clickable', () => {
+    getHealthSpy.and.returnValue(of(healthPayload));
+    fixture.detectChanges();
+
+    const clusterStatusCard = fixture.debugElement.query(
+      By.css('cd-info-card[cardTitle="Cluster Status"]')
+    );
+    const clickableContent = clusterStatusCard.query(By.css('.info-card-content-clickable'));
+    expect(clickableContent).toBeNull();
+    expect(clusterStatusCard.nativeElement.textContent).toEqual(` ${healthPayload.health.status} `);
+  });
+
+  it('should render "Cluster Status" card text that is clickable (popover)', () => {
+    const payload = _.cloneDeep(healthPayload);
+    payload.health['status'] = 'HEALTH_WARN';
+    payload.health['checks'] = [
+      { severity: 'HEALTH_WARN', type: 'WRN', summary: { message: 'fake warning' } }
+    ];
+
+    getHealthSpy.and.returnValue(of(payload));
+    fixture.detectChanges();
+
+    expect(component.permissions.log.read).toBeTruthy();
+
+    const clusterStatusCard = fixture.debugElement.query(
+      By.css('cd-info-card[cardTitle="Cluster Status"]')
+    );
+    const clickableContent = clusterStatusCard.query(By.css('.info-card-content-clickable'));
+    expect(clickableContent.nativeElement.textContent).toEqual(` ${payload.health.status} `);
+  });
 });
index 5ec12fee396d42a802712b26d4497d55b135e291..31ce19f494aaa5aae1fd9882f547f8b5f3922566 100644 (file)
@@ -4,6 +4,8 @@ import { I18n } from '@ngx-translate/i18n-polyfill';
 import * as _ from 'lodash';
 
 import { HealthService } from '../../../shared/api/health.service';
+import { Permissions } from '../../../shared/models/permissions';
+import { AuthStorageService } from '../../../shared/services/auth-storage.service';
 
 @Component({
   selector: 'cd-health',
@@ -13,8 +15,15 @@ import { HealthService } from '../../../shared/api/health.service';
 export class HealthComponent implements OnInit, OnDestroy {
   healthData: any;
   interval: number;
-
-  constructor(private healthService: HealthService, private i18n: I18n) {}
+  permissions: Permissions;
+
+  constructor(
+    private healthService: HealthService,
+    private i18n: I18n,
+    private authStorageService: AuthStorageService
+  ) {
+    this.permissions = this.authStorageService.getPermissions();
+  }
 
   ngOnInit() {
     this.getHealth();
index 890b142d3f1ce40fa04bdee51cfb4161b6d8a944..11343488773b1ff93a490df1ffb4bf91372c5342 100644 (file)
@@ -28,7 +28,7 @@
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">82</context>
+          <context context-type="linenumber">81</context>
         </context-group>
       </trans-unit><trans-unit id="624f596cc3320f5e0a0d7c7346c364e5af9bdd8c" datatype="html">
         <source>Monitors</source>
@@ -38,7 +38,7 @@
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">49</context>
+          <context context-type="linenumber">48</context>
         </context-group>
       </trans-unit><trans-unit id="1a9183778f2c6473d7ccb080f651caa01faaf70c" datatype="html">
         <source>OSDs</source>
@@ -48,7 +48,7 @@
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">58</context>
+          <context context-type="linenumber">57</context>
         </context-group>
       </trans-unit><trans-unit id="4a41f824a35ba01d5bd7be61aa06b3e8145209d0" datatype="html">
         <source>Configuration</source>
@@ -80,7 +80,7 @@
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">191</context>
+          <context context-type="linenumber">190</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/cephfs/cephfs-detail/cephfs-detail.component.html</context>
           <context context-type="sourcefile">app/ceph/cluster/configuration/configuration-details/configuration-details.component.html</context>
           <context context-type="linenumber">102</context>
         </context-group>
-      </trans-unit><trans-unit id="4f951c2d3472dda85872e7b09fbab383463aa4b5" datatype="html">
-        <source>→ See <x id="START_LINK" ctype="x-a" equiv-text="&lt;a&gt;"/>Logs<x id="CLOSE_LINK" ctype="x-a" equiv-text="&lt;/a&gt;"/> for more details.</source>
-        <context-group purpose="location">
-          <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">23</context>
-        </context-group>
-        <context-group purpose="location">
-          <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">241</context>
-        </context-group>
       </trans-unit><trans-unit id="73caac4265ea7314ff061e5a1d78a6361a6dd3b8" datatype="html">
         <source>Cluster Status</source>
         <context-group purpose="location">
         <source>Manager Daemons</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">70</context>
+          <context context-type="linenumber">69</context>
         </context-group>
       </trans-unit><trans-unit id="946ac5dea9921dc09d7b0a63b89535371f283b19" datatype="html">
         <source>Object Gateways</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">91</context>
+          <context context-type="linenumber">90</context>
         </context-group>
       </trans-unit><trans-unit id="ff03fa5bcf37c4da46ad736c1f7d03f959e8ba9a" datatype="html">
         <source>Metadata Servers</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">99</context>
+          <context context-type="linenumber">98</context>
         </context-group>
       </trans-unit><trans-unit id="d817609ba4993eba859409ab71e566168f4d5f5a" datatype="html">
         <source>iSCSI Gateways</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">110</context>
+          <context context-type="linenumber">109</context>
         </context-group>
       </trans-unit><trans-unit id="42c13e50391250ea9379bdf55d5d6c0228c0c8bc" datatype="html">
         <source>Client IOPS</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">126</context>
+          <context context-type="linenumber">125</context>
         </context-group>
       </trans-unit><trans-unit id="52213660b2454d139ada3079a42ec6caf3c3c01e" datatype="html">
         <source>Client Throughput</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">135</context>
+          <context context-type="linenumber">134</context>
         </context-group>
       </trans-unit><trans-unit id="32efd1c3f70e3c5244239de97a2cc95d98534a14" datatype="html">
         <source>Client Read/Write</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">144</context>
+          <context context-type="linenumber">143</context>
         </context-group>
       </trans-unit><trans-unit id="5277e7546d03a767761199b70deb8c77a921b390" datatype="html">
         <source>Client Recovery</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">162</context>
+          <context context-type="linenumber">161</context>
         </context-group>
       </trans-unit><trans-unit id="6d9a9f55046891733ef71170e7652063765eb542" datatype="html">
         <source>Scrub</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">171</context>
+          <context context-type="linenumber">170</context>
         </context-group>
       </trans-unit><trans-unit id="3cc9c2ae277393b3946b38c088dabff671b1ee1b" datatype="html">
         <source>Performance</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">120</context>
+          <context context-type="linenumber">119</context>
         </context-group>
       </trans-unit><trans-unit id="88f383269db2d32cccee9e936fe549dccb9fdbf4" datatype="html">
         <source>Raw Capacity</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">201</context>
+          <context context-type="linenumber">200</context>
         </context-group>
       </trans-unit><trans-unit id="afdb601c16162f2c798b16a2920955f1cc6a20aa" datatype="html">
         <source>Objects</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">214</context>
+          <context context-type="linenumber">213</context>
         </context-group>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/block/rbd-details/rbd-details.component.html</context>
         <source>PGs per OSD</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">223</context>
+          <context context-type="linenumber">222</context>
         </context-group>
       </trans-unit><trans-unit id="498a109c6e9e94f1966de01aa0326f7f0ac6fb52" datatype="html">
         <source>PG Status</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">232</context>
+          <context context-type="linenumber">231</context>
         </context-group>
       </trans-unit><trans-unit id="ce9dfdc6dccb28dc75a78c704e09dc18fb02dcfa" datatype="html">
         <source>Capacity</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
-          <context context-type="linenumber">182</context>
+          <context context-type="linenumber">181</context>
+        </context-group>
+      </trans-unit><trans-unit id="44ecac93d67c6a671198091c2270354f80322327" datatype="html">
+        <source><x id="START_ITALIC_TEXT" ctype="x-i" equiv-text="&lt;i&gt;"/><x id="CLOSE_ITALIC_TEXT" ctype="x-i" equiv-text="&lt;/i&gt;"/> See <x id="START_LINK" ctype="x-a" equiv-text="&lt;a&gt;"/>Logs<x id="CLOSE_LINK" ctype="x-a" equiv-text="&lt;/a&gt;"/> for more details.</source>
+        <context-group purpose="location">
+          <context context-type="sourcefile">app/ceph/dashboard/health/health.component.html</context>
+          <context context-type="linenumber">265</context>
         </context-group>
       </trans-unit><trans-unit id="f0b5d789d42c0e69348e5fe0037fcbf5b5fbbdcc" datatype="html">
         <source>Move an image to trash</source>