Skip to content

Commit

Permalink
Merge pull request #220 from nmaas-platform/216-vlab-manager-not-assi…
Browse files Browse the repository at this point in the history
…gned-to-any-domain-has-access-to-application-subscriptions

in global domain display subscriptions only to system admin
  • Loading branch information
llopat authored Apr 4, 2024
2 parents c6c2951 + 6adcca6 commit b3cbfeb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/app/shared/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ul *ngIf="authService.isLogged()" class="nav navbar-nav navbar-left">
<li [routerLinkActiveOptions]="{exact:true}" [routerLinkActive]="['active']"><a
[routerLink]="['/']">{{ 'NAVBAR.MARKET' | translate }}</a></li>
<li *ngIf="checkUserRole()" [routerLinkActiveOptions]="{exact:true}"
<li *ngIf="checkUserRole() && shouldDisplaySubscriptions()" [routerLinkActiveOptions]="{exact:true}"
[routerLinkActive]="['active']"><a
[routerLink]="['/subscriptions']">{{ 'NAVBAR.SUBSCRIPTIONS' | translate }}</a></li>
<li *ngIf="!isOnlyGuestInGlobalDomain()"
Expand Down
8 changes: 7 additions & 1 deletion src/app/shared/navbar/navbar.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';

import {NavbarComponent} from './navbar.component';
import {TranslateFakeLoader, TranslateLoader, TranslateModule} from '@ngx-translate/core';
Expand All @@ -10,6 +10,7 @@ import {Component, Directive, Input} from '@angular/core';
import {InternationalizationService} from '../../service/internationalization.service';
import {HttpClientTestingModule} from '@angular/common/http/testing';
import {DatePipe} from '@angular/common';
import {UserDataService} from '../../service/userdata.service';

@Component({
selector: 'nmaas-domain-filter',
Expand Down Expand Up @@ -40,6 +41,7 @@ describe('NavbarComponent_Shared', () => {
let languageService: InternationalizationService;
let domainService: DomainService;
let authService: AuthService;
let userDataService: UserDataService;

beforeEach(waitForAsync(() => {
const mockDomainService = jasmine.createSpyObj(['getGlobalDomainId']);
Expand All @@ -52,6 +54,8 @@ describe('NavbarComponent_Shared', () => {
mockAuthService.hasRole.and.returnValue(false);
mockAuthService.getDomains.and.returnValue([]);
mockAuthService.getRoles.and.returnValue([]);
const mockUserDataService = jasmine.createSpyObj(['selectedDomainId'])
mockUserDataService.selectedDomainId.and.returnValue(1)

TestBed.configureTestingModule({
declarations: [
Expand All @@ -74,6 +78,7 @@ describe('NavbarComponent_Shared', () => {
{provide: DomainService, useValue: mockDomainService},
{provide: InternationalizationService, useValue: mockLanguageService},
{provide: AuthService, useValue: mockAuthService},
{provide: UserDataService, useValue: userDataService},
DatePipe
]
}).compileComponents().then((result) => {
Expand All @@ -87,6 +92,7 @@ describe('NavbarComponent_Shared', () => {
languageService = fixture.debugElement.injector.get(InternationalizationService);
domainService = fixture.debugElement.injector.get(DomainService);
authService = fixture.debugElement.injector.get(AuthService);
userDataService = fixture.debugElement.injector.get(UserDataService);
// future use
// spyOn(languageService, 'getEnabledLanguages').and.returnValue(of(['en', 'fr', 'pl']));
// spyOn(languageService, 'shouldUpdate').and.returnValue(false);
Expand Down
12 changes: 11 additions & 1 deletion src/app/shared/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {DomainService} from '../../service';
import {InternationalizationService} from '../../service/internationalization.service';
import {ModalNotificationSendComponent} from '../modal/modal-notification-send/modal-notification-send.component';
import {DatePipe} from '@angular/common';
import {UserDataService} from '../../service/userdata.service';

@Component({
selector: 'app-navbar',
Expand Down Expand Up @@ -34,7 +35,8 @@ export class NavbarComponent implements OnInit {
private translate: TranslateService,
private datePipe: DatePipe,
private languageService: InternationalizationService,
private domainService: DomainService) {
private domainService: DomainService,
private userDataService: UserDataService) {
}

useLanguage(language: string) {
Expand Down Expand Up @@ -101,4 +103,12 @@ export class NavbarComponent implements OnInit {
&& this.authService.getDomains().length === 1 // no roles in other domains
}

public shouldDisplaySubscriptions() {
let currentDomainId = undefined;
const globalDomainId = this.domainService.getGlobalDomainId();
this.userDataService.selectedDomainId.subscribe(id => currentDomainId = id)
const isGlobal = currentDomainId === globalDomainId
const isSystemAdmin = this.authService.hasDomainRole(globalDomainId, 'ROLE_SYSTEM_ADMIN')
return !isGlobal ? true : isSystemAdmin
}
}

0 comments on commit b3cbfeb

Please sign in to comment.