]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: check if user has config-opt permissions before retrieving settings. 32827/head
authorAlfonso Martínez <almartin@redhat.com>
Tue, 21 Jan 2020 12:49:02 +0000 (13:49 +0100)
committerAlfonso Martínez <almartin@redhat.com>
Tue, 4 Feb 2020 11:11:57 +0000 (12:11 +0100)
Fixes: https://tracker.ceph.com/issues/43595
Signed-off-by: Alfonso Martínez <almartin@redhat.com>
(cherry picked from commit ea1c8c7ef7f494208aec1c59d12fec2da759784a)

 Conflicts:
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/components/notifications-sidebar/notifications-sidebar.component.ts

src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts

index 29dc31546895bc0e254c5363f667d7f10173e052..8e1662f41925c5f6023fe2eb07031686636406b1 100644 (file)
@@ -2,11 +2,15 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
 
 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
 import { AppModule } from '../../../app.module';
+import { PrometheusService } from '../../../shared/api/prometheus.service';
+import { Permissions } from '../../../shared/models/permissions';
+import { AuthStorageService } from '../../../shared/services/auth-storage.service';
 import { NavigationComponent } from './navigation.component';
 
 describe('NavigationComponent', () => {
   let component: NavigationComponent;
   let fixture: ComponentFixture<NavigationComponent>;
+  let ifAlertmanagerConfiguredSpy: jasmine.Spy;
 
   configureTestBed({
     imports: [AppModule],
@@ -14,12 +18,30 @@ describe('NavigationComponent', () => {
   });
 
   beforeEach(() => {
+    ifAlertmanagerConfiguredSpy = spyOn(
+      TestBed.get(PrometheusService),
+      'ifAlertmanagerConfigured'
+    ).and.stub();
     fixture = TestBed.createComponent(NavigationComponent);
     component = fixture.componentInstance;
     fixture.detectChanges();
   });
 
-  it('should create', () => {
+  it('should create and PrometheusService methods should not have been called', () => {
     expect(component).toBeTruthy();
+    expect(ifAlertmanagerConfiguredSpy).toHaveBeenCalledTimes(0);
+  });
+
+  it('PrometheusService methods should have been called', () => {
+    const authStorageServiceSpy = spyOn(
+      TestBed.get(AuthStorageService),
+      'getPermissions'
+    ).and.returnValue(new Permissions({ 'config-opt': ['read'] }));
+    TestBed.overrideProvider(AuthStorageService, { useValue: authStorageServiceSpy });
+    fixture = TestBed.createComponent(NavigationComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+
+    expect(ifAlertmanagerConfiguredSpy).toHaveBeenCalledTimes(1);
   });
 });
index 5f8d1f5a7e96a8c20645b500f41ee9de10afed74..3e0cd6f1d13fd136c937ef072a18b661cd6aa34c 100644 (file)
@@ -39,7 +39,9 @@ export class NavigationComponent implements OnInit {
       }
       this.summaryData = data;
     });
-    this.prometheusService.ifAlertmanagerConfigured(() => (this.prometheusConfigured = true));
+    if (this.permissions.configOpt.read) {
+      this.prometheusService.ifAlertmanagerConfigured(() => (this.prometheusConfigured = true));
+    }
   }
 
   blockHealthColor() {