feat(console): grpc web interceptors, cleanup services (#631)

* managementservice, authservice, change all refs

* refactor grpc auth

* fix references

* interceptor logic

* new interceptor

* appinitializers, environment loader, interceptors

* remove circular dep

* init authconfig in grpc service

* authconfig

* lint

* update mgmt service

* fix references

* update clientid, fix interceptor

* rm unused authconfig

* todo auth interceptor
This commit is contained in:
Max Peintner
2020-08-29 10:43:35 +02:00
committed by GitHub
parent 40b8faaddd
commit eeea1f1c4b
81 changed files with 1877 additions and 2639 deletions
@@ -2,8 +2,8 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Router } from '@angular/router';
import { AuthConfig } from 'angular-oauth2-oidc';
import { UserProfileView, UserSessionView } from 'src/app/proto/generated/auth_pb';
import { AuthUserService } from 'src/app/services/auth-user.service';
import { AuthService } from 'src/app/services/auth.service';
import { AuthenticationService } from 'src/app/services/authentication.service';
import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
@Component({
selector: 'app-accounts-card',
@@ -17,7 +17,7 @@ export class AccountsCardComponent implements OnInit {
@Output() public close: EventEmitter<void> = new EventEmitter();
public users: UserSessionView.AsObject[] = [];
public loadingUsers: boolean = false;
constructor(public authService: AuthService, private router: Router, private userService: AuthUserService) {
constructor(public authService: AuthenticationService, private router: Router, private userService: GrpcAuthService) {
this.userService.getMyUserSessions().then(sessions => {
this.users = sessions.toObject().userSessionsList;
const index = this.users.findIndex(user => user.loginName === this.profile.preferredLoginName);
@@ -2,7 +2,7 @@ import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { ProjectGrantView, ProjectRole, ProjectView, UserView } from 'src/app/proto/generated/management_pb';
import { AdminService } from 'src/app/services/admin.service';
import { ProjectService } from 'src/app/services/project.service';
import { ManagementService } from 'src/app/services/mgmt.service';
import { ToastService } from 'src/app/services/toast.service';
import { ProjectAutocompleteType } from '../search-project-autocomplete/search-project-autocomplete.component';
@@ -39,7 +39,7 @@ export class MemberCreateDialogComponent {
public showCreationTypeSelector: boolean = false;
constructor(
private projectService: ProjectService,
private mgmtService: ManagementService,
private adminService: AdminService,
public dialogRef: MatDialogRef<MemberCreateDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
@@ -64,14 +64,14 @@ export class MemberCreateDialogComponent {
public loadRoles(): void {
switch (this.creationType) {
case CreationType.PROJECT_GRANTED:
this.projectService.GetProjectGrantMemberRoles().then(resp => {
this.mgmtService.GetProjectGrantMemberRoles().then(resp => {
this.memberRoleOptions = resp.toObject().rolesList;
}).catch(error => {
this.toastService.showError(error);
});
break;
case CreationType.PROJECT_OWNED:
this.projectService.GetProjectMemberRoles().then(resp => {
this.mgmtService.GetProjectMemberRoles().then(resp => {
this.memberRoleOptions = resp.toObject().rolesList;
}).catch(error => {
this.toastService.showError(error);
@@ -2,8 +2,8 @@ import { Component, Input, OnInit } from '@angular/core';
import { BehaviorSubject, from, Observable, of } from 'rxjs';
import { catchError, scan, take, tap } from 'rxjs/operators';
import { Change, Changes } from 'src/app/proto/generated/management_pb';
import { AuthUserService } from 'src/app/services/auth-user.service';
import { MgmtUserService } from 'src/app/services/mgmt-user.service';
import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
import { ManagementService } from 'src/app/services/mgmt.service';
export enum ChangeType {
MYUSER = 'myuser',
@@ -30,7 +30,7 @@ export class ChangesComponent implements OnInit {
loading: Observable<boolean> = this._loading.asObservable();
public data!: Observable<Change.AsObject[]>;
public changes!: Changes.AsObject;
constructor(private mgmtUserService: MgmtUserService, private authUserService: AuthUserService) { }
constructor(private mgmtUserService: ManagementService, private authUserService: GrpcAuthService) { }
ngOnInit(): void {
this.init();
@@ -3,7 +3,7 @@ import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
import { BehaviorSubject, from, Observable, of } from 'rxjs';
import { catchError, finalize, map } from 'rxjs/operators';
import { ProjectMember, ProjectMemberSearchResponse, ProjectType } from 'src/app/proto/generated/management_pb';
import { ProjectService } from 'src/app/services/project.service';
import { ManagementService } from 'src/app/services/mgmt.service';
/**
* Data source for the ProjectMembers view. This class should
@@ -18,7 +18,7 @@ export class ProjectMembersDataSource extends DataSource<ProjectMember.AsObject>
private loadingSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
public loading$: Observable<boolean> = this.loadingSubject.asObservable();
constructor(private projectService: ProjectService) {
constructor(private mgmtService: ManagementService) {
super();
}
@@ -31,9 +31,9 @@ export class ProjectMembersDataSource extends DataSource<ProjectMember.AsObject>
const promise: Promise<ProjectMemberSearchResponse> | undefined =
projectType === ProjectType.PROJECTTYPE_OWNED ?
this.projectService.SearchProjectMembers(projectId, pageSize, offset) :
this.mgmtService.SearchProjectMembers(projectId, pageSize, offset) :
projectType === ProjectType.PROJECTTYPE_GRANTED && grantId ?
this.projectService.SearchProjectGrantMembers(projectId,
this.mgmtService.SearchProjectGrantMembers(projectId,
grantId, pageSize, offset) : undefined;
if (promise) {
from(promise).pipe(
@@ -7,7 +7,7 @@ import { MatTable } from '@angular/material/table';
import { ActivatedRoute } from '@angular/router';
import { take } from 'rxjs/operators';
import { ProjectGrantView, ProjectMember, ProjectType, ProjectView, UserView } from 'src/app/proto/generated/management_pb';
import { ProjectService } from 'src/app/services/project.service';
import { ManagementService } from 'src/app/services/mgmt.service';
import { ToastService } from 'src/app/services/toast.service';
import { CreationType, MemberCreateDialogComponent } from '../add-member-dialog/member-create-dialog.component';
@@ -36,7 +36,7 @@ export class ProjectMembersComponent {
public displayedColumns: string[] = ['select', 'userId', 'firstname', 'lastname', 'username', 'email', 'roles'];
constructor(
private projectService: ProjectService,
private mgmtService: ManagementService,
private dialog: MatDialog,
private toast: ToastService,
private route: ActivatedRoute) {
@@ -48,17 +48,17 @@ export class ProjectMembersComponent {
this.route.params.subscribe(params => {
this.grantId = params.grantid;
if (this.projectType === ProjectType.PROJECTTYPE_OWNED) {
this.projectService.GetProjectById(params.projectid).then(project => {
this.mgmtService.GetProjectById(params.projectid).then(project => {
this.project = project.toObject();
this.projectName = this.project.name;
this.dataSource = new ProjectMembersDataSource(this.projectService);
this.dataSource = new ProjectMembersDataSource(this.mgmtService);
this.dataSource.loadMembers(this.project.projectId, this.projectType, 0, this.INITIALPAGESIZE);
});
} else if (this.projectType === ProjectType.PROJECTTYPE_GRANTED) {
this.projectService.GetGrantedProjectByID(params.projectid, params.grantid).then(project => {
this.mgmtService.GetGrantedProjectByID(params.projectid, params.grantid).then(project => {
this.project = project.toObject();
this.projectName = this.project.projectName;
this.dataSource = new ProjectMembersDataSource(this.projectService);
this.dataSource = new ProjectMembersDataSource(this.mgmtService);
this.dataSource.loadMembers(this.project.projectId,
this.projectType,
0,
@@ -73,13 +73,13 @@ export class ProjectMembersComponent {
public getRoleOptions(): void {
if (this.projectType === ProjectType.PROJECTTYPE_GRANTED) {
this.projectService.GetProjectGrantMemberRoles().then(resp => {
this.mgmtService.GetProjectGrantMemberRoles().then(resp => {
this.memberRoleOptions = resp.toObject().rolesList;
}).catch(error => {
this.toast.showError(error);
});
} else if (this.projectType === ProjectType.PROJECTTYPE_OWNED) {
this.projectService.GetProjectMemberRoles().then(resp => {
this.mgmtService.GetProjectMemberRoles().then(resp => {
this.memberRoleOptions = resp.toObject().rolesList;
}).catch(error => {
this.toast.showError(error);
@@ -90,13 +90,13 @@ export class ProjectMembersComponent {
public removeProjectMemberSelection(): void {
Promise.all(this.selection.selected.map(member => {
if (this.projectType === ProjectType.PROJECTTYPE_OWNED) {
return this.projectService.RemoveProjectMember(this.project.projectId, member.userId).then(() => {
return this.mgmtService.RemoveProjectMember(this.project.projectId, member.userId).then(() => {
this.toast.showInfo('PROJECT.TOAST.MEMBERREMOVED', true);
}).catch(error => {
this.toast.showError(error);
});
} else if (this.projectType === ProjectType.PROJECTTYPE_GRANTED) {
return this.projectService.RemoveProjectGrantMember(this.project.projectId, this.grantId,
return this.mgmtService.RemoveProjectGrantMember(this.project.projectId, this.grantId,
member.userId).then(() => {
this.toast.showInfo('PROJECT.TOAST.MEMBERREMOVED', true);
}).catch(error => {
@@ -134,10 +134,10 @@ export class ProjectMembersComponent {
if (users && users.length && roles && roles.length) {
Promise.all(users.map(user => {
if (this.projectType === ProjectType.PROJECTTYPE_OWNED) {
return this.projectService.AddProjectMember(this.project.projectId, user.id, roles);
return this.mgmtService.AddProjectMember(this.project.projectId, user.id, roles);
} else if (this.projectType === ProjectType.PROJECTTYPE_GRANTED) {
return this.projectService.AddProjectGrantMember(this.project.projectId, this.grantId,
return this.mgmtService.AddProjectGrantMember(this.project.projectId, this.grantId,
user.id, roles);
}
})).then(() => {
@@ -152,14 +152,14 @@ export class ProjectMembersComponent {
updateRoles(member: ProjectMember.AsObject, selectionChange: MatSelectChange): void {
if (this.projectType === ProjectType.PROJECTTYPE_OWNED) {
this.projectService.ChangeProjectMember(this.project.projectId, member.userId, selectionChange.value)
this.mgmtService.ChangeProjectMember(this.project.projectId, member.userId, selectionChange.value)
.then((newmember: ProjectMember) => {
this.toast.showInfo('PROJECT.TOAST.MEMBERCHANGED', true);
}).catch(error => {
this.toast.showError(error);
});
} else if (this.projectType === ProjectType.PROJECTTYPE_GRANTED) {
this.projectService.ChangeProjectGrantMember(this.project.projectId,
this.mgmtService.ChangeProjectGrantMember(this.project.projectId,
this.grantId, member.userId, selectionChange.value)
.then((newmember: ProjectMember) => {
this.toast.showInfo('PROJECT.TOAST.MEMBERCHANGED', true);
@@ -1,7 +1,7 @@
import { Component, Inject, OnInit } from '@angular/core';
import { AbstractControl, FormControl, FormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { ProjectService } from 'src/app/services/project.service';
import { ManagementService } from 'src/app/services/mgmt.service';
import { ToastService } from 'src/app/services/toast.service';
@Component({
@@ -13,7 +13,7 @@ export class ProjectRoleDetailComponent implements OnInit {
public projectId: string = '';
public formGroup!: FormGroup;
constructor(private projectService: ProjectService, private toast: ToastService,
constructor(private mgmtService: ManagementService, private toast: ToastService,
public dialogRef: MatDialogRef<ProjectRoleDetailComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) {
@@ -32,7 +32,7 @@ export class ProjectRoleDetailComponent implements OnInit {
submitForm(): void {
if (this.formGroup.valid && this.key?.value && this.group?.value && this.displayName?.value) {
this.projectService.ChangeProjectRole(this.projectId, this.key.value, this.key.value, this.group.value)
this.mgmtService.ChangeProjectRole(this.projectId, this.key.value, this.key.value, this.group.value)
.then(() => {
this.toast.showInfo('PROJECT.TOAST.ROLECHANGED', true);
this.dialogRef.close(true);
@@ -3,7 +3,7 @@ import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
import { BehaviorSubject, from, Observable, of } from 'rxjs';
import { catchError, finalize, map } from 'rxjs/operators';
import { ProjectRole } from 'src/app/proto/generated/management_pb';
import { ProjectService } from 'src/app/services/project.service';
import { ManagementService } from 'src/app/services/mgmt.service';
/**
* Data source for the ProjectMembers view. This class should
@@ -18,7 +18,7 @@ export class ProjectRolesDataSource extends DataSource<ProjectRole.AsObject> {
private loadingSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
public loading$: Observable<boolean> = this.loadingSubject.asObservable();
constructor(private projectService: ProjectService) {
constructor(private mgmtService: ManagementService) {
super();
}
@@ -26,7 +26,7 @@ export class ProjectRolesDataSource extends DataSource<ProjectRole.AsObject> {
const offset = pageIndex * pageSize;
this.loadingSubject.next(true);
from(this.projectService.SearchProjectRoles(projectId, pageSize, offset)).pipe(
from(this.mgmtService.SearchProjectRoles(projectId, pageSize, offset)).pipe(
map(resp => {
const response = resp.toObject();
this.totalResult = response.totalResult;
@@ -5,7 +5,7 @@ import { MatPaginator } from '@angular/material/paginator';
import { MatTable } from '@angular/material/table';
import { tap } from 'rxjs/operators';
import { ProjectRole } from 'src/app/proto/generated/management_pb';
import { ProjectService } from 'src/app/services/project.service';
import { ManagementService } from 'src/app/services/mgmt.service';
import { ToastService } from 'src/app/services/toast.service';
import { ProjectRoleDetailComponent } from './project-role-detail/project-role-detail.component';
@@ -30,8 +30,8 @@ export class ProjectRolesComponent implements AfterViewInit, OnInit {
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
public displayedColumns: string[] = ['select', 'key', 'displayname', 'group', 'creationDate'];
constructor(private projectService: ProjectService, private toast: ToastService, private dialog: MatDialog) {
this.dataSource = new ProjectRolesDataSource(this.projectService);
constructor(private mgmtService: ManagementService, private toast: ToastService, private dialog: MatDialog) {
this.dataSource = new ProjectRolesDataSource(this.mgmtService);
}
public ngOnInit(): void {
@@ -83,7 +83,7 @@ export class ProjectRolesComponent implements AfterViewInit, OnInit {
});
return Promise.all(this.selection.selected.map(role => {
return this.projectService.RemoveProjectRole(role.projectId, role.key);
return this.mgmtService.RemoveProjectRole(role.projectId, role.key);
})).then(() => {
this.toast.showInfo('PROJECT.TOAST.ROLEREMOVED', true);
indexes.forEach(index => {
@@ -99,7 +99,7 @@ export class ProjectRolesComponent implements AfterViewInit, OnInit {
}
public removeRole(role: ProjectRole.AsObject, index: number): void {
this.projectService
this.mgmtService
.RemoveProjectRole(role.projectId, role.key)
.then(() => {
this.toast.showInfo('PROJECT.TOAST.ROLEREMOVED', true);
@@ -14,7 +14,7 @@ import {
ProjectView,
SearchMethod,
} from 'src/app/proto/generated/management_pb';
import { ProjectService } from 'src/app/services/project.service';
import { ManagementService } from 'src/app/services/mgmt.service';
export enum ProjectAutocompleteType {
@@ -47,7 +47,7 @@ export class SearchProjectAutocompleteComponent {
| ProjectView.AsObject
| ProjectView.AsObject[]
> = new EventEmitter();
constructor(private projectService: ProjectService) {
constructor(private mgmtService: ManagementService) {
this.myControl.valueChanges
.pipe(
debounceTime(200),
@@ -60,13 +60,13 @@ export class SearchProjectAutocompleteComponent {
switch (this.autocompleteType) {
case ProjectAutocompleteType.PROJECT_GRANTED:
return from(this.projectService.SearchGrantedProjects(10, 0, [query]));
return from(this.mgmtService.SearchGrantedProjects(10, 0, [query]));
case ProjectAutocompleteType.PROJECT_OWNED:
return from(this.projectService.SearchProjects(10, 0, [query]));
return from(this.mgmtService.SearchProjects(10, 0, [query]));
default:
return forkJoin([
from(this.projectService.SearchGrantedProjects(10, 0, [query])),
from(this.projectService.SearchProjects(10, 0, [query])),
from(this.mgmtService.SearchGrantedProjects(10, 0, [query])),
from(this.mgmtService.SearchProjects(10, 0, [query])),
]);
}
}),
@@ -11,7 +11,7 @@ import {
ProjectRoleSearchQuery,
SearchMethod,
} from 'src/app/proto/generated/management_pb';
import { ProjectService } from 'src/app/services/project.service';
import { ManagementService } from 'src/app/services/mgmt.service';
import { ToastService } from 'src/app/services/toast.service';
@@ -35,7 +35,7 @@ export class SearchRolesAutocompleteComponent {
@Input() public projectId: string = '';
@Input() public singleOutput: boolean = false;
@Output() public selectionChanged: EventEmitter<ProjectRole.AsObject[] | ProjectRole.AsObject> = new EventEmitter();
constructor(private projectService: ProjectService, private toast: ToastService) {
constructor(private mgmtService: ManagementService, private toast: ToastService) {
this.myControl.valueChanges
.pipe(
debounceTime(200),
@@ -45,7 +45,7 @@ export class SearchRolesAutocompleteComponent {
query.setKey(ProjectRoleSearchKey.PROJECTROLESEARCHKEY_DISPLAY_NAME);
query.setMethod(SearchMethod.SEARCHMETHOD_CONTAINS_IGNORE_CASE);
query.setValue(value);
return from(this.projectService.SearchProjectRoles(this.projectId, 10, 0, [query]));
return from(this.mgmtService.SearchProjectRoles(this.projectId, 10, 0, [query]));
}),
).subscribe((roles) => {
this.isLoading = false;
@@ -5,8 +5,8 @@ import { MatAutocomplete, MatAutocompleteSelectedEvent } from '@angular/material
import { MatChipInputEvent } from '@angular/material/chips';
import { from, of, Subject } from 'rxjs';
import { debounceTime, switchMap, takeUntil, tap } from 'rxjs/operators';
import { SearchMethod, UserView, UserSearchKey, UserSearchQuery } from 'src/app/proto/generated/management_pb';
import { MgmtUserService } from 'src/app/services/mgmt-user.service';
import { SearchMethod, UserSearchKey, UserSearchQuery, UserView } from 'src/app/proto/generated/management_pb';
import { ManagementService } from 'src/app/services/mgmt.service';
import { ToastService } from 'src/app/services/toast.service';
export enum UserTarget {
@@ -41,7 +41,7 @@ export class SearchUserAutocompleteComponent {
@Input() public singleOutput: boolean = false;
private unsubscribed$: Subject<void> = new Subject();
constructor(private userService: MgmtUserService, private toast: ToastService) {
constructor(private userService: ManagementService, private toast: ToastService) {
this.getFilteredResults();
}
@@ -10,7 +10,7 @@ import {
UserGrantSearchResponse,
UserGrantView,
} from 'src/app/proto/generated/management_pb';
import { MgmtUserService } from 'src/app/services/mgmt-user.service';
import { ManagementService } from 'src/app/services/mgmt.service';
export enum UserGrantContext {
// AUTHUSER = 'authuser',
@@ -27,7 +27,7 @@ export class UserGrantsDataSource extends DataSource<UserGrant.AsObject> {
private loadingSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
public loading$: Observable<boolean> = this.loadingSubject.asObservable();
constructor(private userService: MgmtUserService) {
constructor(private userService: ManagementService) {
super();
}
@@ -12,8 +12,7 @@ import {
UserGrantSearchQuery,
UserGrantView,
} from 'src/app/proto/generated/management_pb';
import { MgmtUserService } from 'src/app/services/mgmt-user.service';
import { ProjectService } from 'src/app/services/project.service';
import { ManagementService } from 'src/app/services/mgmt.service';
import { ToastService } from 'src/app/services/toast.service';
import { UserGrantContext, UserGrantsDataSource } from './user-grants-datasource';
@@ -51,8 +50,8 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
public UserGrantContext: any = UserGrantContext;
constructor(
private userService: MgmtUserService,
private projectService: ProjectService,
private userService: ManagementService,
private mgmtService: ManagementService,
private toast: ToastService,
) { }
@@ -125,7 +124,7 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
}
public getGrantRoleOptions(grantId: string, projectId: string): void {
this.projectService.GetGrantedProjectByID(projectId, grantId).then(resp => {
this.mgmtService.GetGrantedProjectByID(projectId, grantId).then(resp => {
this.loadedGrantId = projectId;
this.grantRoleOptions = resp.toObject().roleKeysList;
}).catch(error => {
@@ -134,7 +133,7 @@ export class UserGrantsComponent implements OnInit, AfterViewInit {
}
public getProjectRoleOptions(projectId: string): void {
this.projectService.SearchProjectRoles(projectId, 100, 0).then(resp => {
this.mgmtService.SearchProjectRoles(projectId, 100, 0).then(resp => {
this.loadedProjectId = projectId;
this.projectRoleOptions = resp.toObject().resultList;
});