From 11ca48830e6dd8949864e49ccadf15eb12a30ad8 Mon Sep 17 00:00:00 2001 From: alfonsomthd Date: Mon, 3 Dec 2018 13:54:05 +0100 Subject: [PATCH] mgr/dashboard: 'Logs' links permission in Landing Page MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - '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 --- .../dashboard/health/health.component.html | 15 ++++-- .../dashboard/health/health.component.spec.ts | 41 +++++++++++++- .../ceph/dashboard/health/health.component.ts | 13 ++++- .../frontend/src/locale/messages.xlf | 54 +++++++++---------- 4 files changed, 86 insertions(+), 37 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.html index 54d9e40bd15..a5f9014bd75 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.html @@ -19,8 +19,7 @@ *ngIf="healthData.health?.status"> - +
  • {{ check.type }}: {{ check.summary.message }} @@ -39,7 +38,7 @@ {{ healthData.health.status }} - +
    {{ healthData.health.status }}
    @@ -237,8 +236,7 @@ (click)="pgStatusTarget.toggle()" *ngIf="healthData.pg_info"> - +
    • {{ pgStatesText.key }}: {{ pgStatesText.value }} @@ -260,4 +258,11 @@ + + + + + + diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts index f4de0412581..847121617ae 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts @@ -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} `); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts index 5ec12fee396..31ce19f494a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts @@ -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(); diff --git a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf index 890b142d3f1..11343488773 100644 --- a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf +++ b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf @@ -28,7 +28,7 @@ app/ceph/dashboard/health/health.component.html - 82 + 81 Monitors @@ -38,7 +38,7 @@ app/ceph/dashboard/health/health.component.html - 49 + 48 OSDs @@ -48,7 +48,7 @@ app/ceph/dashboard/health/health.component.html - 58 + 57 Configuration @@ -80,7 +80,7 @@ app/ceph/dashboard/health/health.component.html - 191 + 190 app/ceph/cephfs/cephfs-detail/cephfs-detail.component.html @@ -2537,16 +2537,6 @@ app/ceph/cluster/configuration/configuration-details/configuration-details.component.html 102 - - → See Logs for more details. - - app/ceph/dashboard/health/health.component.html - 23 - - - app/ceph/dashboard/health/health.component.html - 241 - Cluster Status @@ -2557,73 +2547,73 @@ Manager Daemons app/ceph/dashboard/health/health.component.html - 70 + 69 Object Gateways app/ceph/dashboard/health/health.component.html - 91 + 90 Metadata Servers app/ceph/dashboard/health/health.component.html - 99 + 98 iSCSI Gateways app/ceph/dashboard/health/health.component.html - 110 + 109 Client IOPS app/ceph/dashboard/health/health.component.html - 126 + 125 Client Throughput app/ceph/dashboard/health/health.component.html - 135 + 134 Client Read/Write app/ceph/dashboard/health/health.component.html - 144 + 143 Client Recovery app/ceph/dashboard/health/health.component.html - 162 + 161 Scrub app/ceph/dashboard/health/health.component.html - 171 + 170 Performance app/ceph/dashboard/health/health.component.html - 120 + 119 Raw Capacity app/ceph/dashboard/health/health.component.html - 201 + 200 Objects app/ceph/dashboard/health/health.component.html - 214 + 213 app/ceph/block/rbd-details/rbd-details.component.html @@ -2633,19 +2623,25 @@ PGs per OSD app/ceph/dashboard/health/health.component.html - 223 + 222 PG Status app/ceph/dashboard/health/health.component.html - 232 + 231 Capacity app/ceph/dashboard/health/health.component.html - 182 + 181 + + + See Logs for more details. + + app/ceph/dashboard/health/health.component.html + 265 Move an image to trash -- 2.39.5