Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide app vars tab if user is not a space developer #3247

Merged
merged 5 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions secrets.yaml.sys
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# E2E Configuration file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be in the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No


consoleUsers:
admin:
username: admin
password: changeme
nonAdmin:
username: user
password: changeme

endpoints:
cf:
- name: cf
url: https://api.10.86.2.89.xip.io
skipSSLValidation: true
testOrg: e2e
testSpace: e2e
testService: app-autoscaler
services:
bindApp: go-env
publicService:
name: public-service
privateService:
name: private-service
invalidOrgName: test-e2e
invalidSpaceName: test-e2e
spaceScopedService:
name: space-scoped-service
invalidOrgName: test-e2e
invalidSpaceName: test-e2e
creds:
admin:
username: admin
password: changeme
nonAdmin:
username: user
password: changeme
- name: regonlycf
url: https://cfinfo.capbristol.com
skipSSLValidation: true
testOrg: e2e
testSpace: e2e
creds:
admin:
username: admin
password: changeme
nonAdmin:
username: e2e
password: changeme

# Skip SSL validation when talking to the backend API for test setup
skipSSLValidation: true

#headless: true
#stratosGitHubApiUrl: https://github.capbristol.com:37070


11 changes: 11 additions & 0 deletions src/frontend/app/features/applications/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
spaceSchemaKey,
spaceWithOrgKey,
stackSchemaKey,
appEnvVarsSchemaKey,
} from '../../store/helpers/entity-factory';
import { createEntityRelationKey } from '../../store/helpers/entity-relations/entity-relations.types';
import { ActionState, rootUpdatingKey } from '../../store/reducers/api-request-reducer/types';
Expand All @@ -47,6 +48,7 @@ import {
EnvVarStratosProject,
} from './application/application-tabs-base/tabs/build-tab/application-env-vars.service';
import { getRoute, isTCPRoute } from './routes/routes.helper';
import { EntityMonitorFactory } from '../../shared/monitors/entity-monitor.factory.service';


export function createGetApplicationAction(guid: string, endpointGuid: string) {
Expand Down Expand Up @@ -213,6 +215,15 @@ export class ApplicationService {
this.appEnvVars = this.appEnvVarsService.createEnvVarsObs(this.appGuid, this.cfGuid);
}

public getApplicationEnvVarsMonitor() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better placed in ApplicationEnvVarsHelper alongside createEnvVarsObs

const factory = new EntityMonitorFactory(this.store);
return factory.create<APIResource<IApp>>(
this.appGuid,
appEnvVarsSchemaKey,
entityFactory(appEnvVarsSchemaKey)
);
}

private constructAmalgamatedObservables() {
// Assign/Amalgamate them to public properties (with mangling if required)
const action = new GetAppStatsAction(this.appGuid, this.cfGuid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CfUserService } from './../../../../shared/data-services/cf-user.service';

import { Component, Inject, NgZone, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { combineLatest as observableCombineLatest, Observable, of as observableOf, Subscription } from 'rxjs';
import { delay, filter, first, map, mergeMap, tap, withLatestFrom, startWith } from 'rxjs/operators';
import { delay, filter, first, map, mergeMap, tap, withLatestFrom, startWith, switchMap } from 'rxjs/operators';
import { IApp, IOrganization, ISpace } from '../../../../core/cf-api.types';
import { CurrentUserPermissions } from '../../../../core/current-user-permissions.config';
import { EntityService } from '../../../../core/entity-service';
import { ConfirmationDialogConfig } from '../../../../shared/components/confirmation-dialog.config';
import { ConfirmationDialogService } from '../../../../shared/components/confirmation-dialog.service';
Expand All @@ -32,6 +32,7 @@ import {
getActionsFromExtensions,
StratosActionType
} from '../../../../core/extension/extension-service';
import { CurrentUserPermissions } from '../../../../core/current-user-permissions.config';

// Confirmation dialogs
const appStopConfirmation = new ConfirmationDialogConfig(
Expand Down Expand Up @@ -110,9 +111,28 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy {
}
});

// Listen for the response to the env vars API call - if it errors then we hide the variables tab
// This is simpler than the code to check permissions since we make the env vars request anyway
const appDoesNotHaveEnvVars$ = this.applicationService.getApplicationEnvVarsMonitor().entityRequest$.pipe(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we should stick to the permissions. That way the user can then refresh the list and still see the env vars. To switch would need to

  1. Add new ENV_VARS_VIEW entry to the CurrentUserPermissions enum in current-user-ermissions.config.ts
  2. Add entry for new enum value to permissionConfigs in the same file (which just needs to be look for space dev)
  3. In application-tabs-base.component.ts import CurrentUserPermissionsService and use it's can function with something like can(<new env vars view enum>, <endppoint guid>, <space giud>)

filter(resp => resp.error || resp.response),
first(),
map(resp => resp.error)
);

this.tabLinks = [
{ link: 'summary', label: 'Summary' },
{ link: 'instances', label: 'Instances' },
{ link: 'routes', label: 'Routes' },
{ link: 'log-stream', label: 'Log Stream' },
{ link: 'services', label: 'Services' },
{ link: 'variables', label: 'Variables', hidden: appDoesNotHaveEnvVars$ },
{ link: 'events', label: 'Events' }
];

// Add any tabs from extensions
this.tabLinks = this.tabLinks.concat(getTabsFromExtensions(StratosTabType.Application));
}

public breadcrumbs$: Observable<IHeaderBreadcrumb[]>;
isFetching$: Observable<boolean>;
applicationActions$: Observable<string[]>;
Expand All @@ -125,15 +145,7 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy {
update => update[this.autoRefreshString] || { busy: false }
));

tabLinks: ISubHeaderTabs[] = [
{ link: 'summary', label: 'Summary' },
{ link: 'instances', label: 'Instances' },
{ link: 'routes', label: 'Routes' },
{ link: 'log-stream', label: 'Log Stream' },
{ link: 'services', label: 'Services' },
{ link: 'variables', label: 'Variables' },
{ link: 'events', label: 'Events' }
];
tabLinks: ISubHeaderTabs[];

private getBreadcrumbs(
application: IApp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
</button>
<div class="tab-nav__inner" #navScroller [ngStyle]="{'margin-bottom.px': isOverflowing ? -(scrollBarWidth) : 0}">
<nav *ngIf="tabs" #nav backgroundColor="primary" mat-tab-nav-bar class="tab-nav">
<a mat-tab-link [ngClass]="{'page-subheader__tab-hidden': (tab.hidden | async)}" class="mat-tab-fit" *ngFor="let tab of tabs" [routerLink]="[tab.link]" routerLinkActive="active-link" #rla="routerLinkActive" [active]="rla.isActive">
{{tab.label}}
</a>
<ng-container *ngFor="let tab of tabs">
<a mat-tab-link *ngIf="tab.hidden ? !(tab.hidden | async) : true" class="mat-tab-fit" [routerLink]="[tab.link]" routerLinkActive="active-link" #rla="routerLinkActive" [active]="rla.isActive">
{{tab.label}}
</a>
</ng-container>
</nav>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
position: relative;
height: 46px;
}
&__tab-hidden {
display: none;
}
}

.tab-nav {
Expand Down