feat: rehauled console (#3525)

* new console

* move npm ci to angular build

* rel path for assets

* local grpc copy

* login policy, rm clear views, features rel path

* lock

Co-authored-by: Livio Amstutz <[email protected]>
This commit is contained in:
Max Peintner
2022-04-28 10:35:02 +00:00
committed by GitHub
co-authored by Livio Amstutz
parent 00f7dbe875
commit 08ae39ae19
668 changed files with 47746 additions and 19117 deletions
@@ -1,77 +1,69 @@
<div class="container">
<div class="max-width-container">
<div class="enlarged-container">
<div class="abort-container">
<button (click)="close()" mat-icon-button>
<mat-icon>close</mat-icon>
</button>
<h1 class="abort">{{ 'GRANTS.CREATE.TITLE' | translate }}</h1><span class="abort-2">Step
{{ currentCreateStep }} of
{{ STEPS }}</span>
<button (click)="close()" mat-icon-button>
<mat-icon>close</mat-icon>
</button>
<h1 class="abort">{{ 'GRANTS.CREATE.TITLE' | translate }}</h1><span class="abort-2">Step
{{ currentCreateStep }} of
{{ STEPS }}</span>
</div>
<ng-container *ngIf="currentCreateStep === 1">
<p class="desc">
{{'PROJECT.GRANT.CREATE.ORG_DESCRIPTION' | translate: org}}
<br>
{{'PROJECT.GRANT.CREATE.ORG_DESCRIPTION_DESC' | translate}}
<div class="user-grant-create-content">
<ng-container *ngIf="currentCreateStep === 1">
<p class="user-grant-create-desc cnsl-secondary-text">
{{'PROJECT.GRANT.CREATE.ORG_DESCRIPTION' | translate: org}}
<br>
{{'PROJECT.GRANT.CREATE.ORG_DESCRIPTION_DESC' | translate}}
</p>
<ng-container>
<h2>{{'PROJECT.GRANT.CREATE.SEL_USER' | translate}}</h2>
<h2>{{'PROJECT.GRANT.CREATE.SEL_USER' | translate}}</h2>
<cnsl-search-user-autocomplete class="block" [singleOutput]="true" [users]="user ? [user] : []"
(selectionChanged)="selectUser($event)"
[target]="context === UserGrantContext.USER ? UserTarget.EXTERNAL : UserTarget.SELF">
</cnsl-search-user-autocomplete>
<cnsl-search-user-autocomplete [editState]="context !== UserGrantContext.USER" class="block"
[users]="user ? [user] : []" (selectionChanged)="selectUsers($event)" [target]="UserTarget.SELF">
</cnsl-search-user-autocomplete>
</ng-container>
<ng-container *ngIf="context && (context === UserGrantContext.USER || context === UserGrantContext.NONE)">
<h2>{{'PROJECT.GRANT.CREATE.SEL_PROJECT' | translate}}</h2>
<h2 class="project-search">{{'PROJECT.GRANT.CREATE.SEL_PROJECT' | translate}}</h2>
<cnsl-search-project-autocomplete class="block" [singleOutput]="true"
(selectionChanged)="selectProject($event)">
</cnsl-search-project-autocomplete>
<cnsl-search-project-autocomplete class="block"
(selectionChanged)="selectProject($event.project, $event.type)">
</cnsl-search-project-autocomplete>
</ng-container>
</ng-container>
</ng-container>
<ng-container *ngIf="currentCreateStep === STEPS">
<ng-container *ngIf="currentCreateStep === STEPS">
<h1>{{'PROJECT.GRANT.CREATE.SEL_ROLES' | translate}}</h1>
<ng-container
*ngIf="$any(project)?.id && (context === UserGrantContext.OWNED_PROJECT || context === UserGrantContext.USER || context === UserGrantContext.NONE)">
<cnsl-card>
<cnsl-project-roles (changedSelection)="selectRoles($event)" [projectId]="projectId">
</cnsl-project-roles>
</cnsl-card>
</ng-container>
<ng-container
*ngIf="$any(project)?.projectId && (context === UserGrantContext.GRANTED_PROJECT || context === UserGrantContext.USER || context === UserGrantContext.NONE) && grantedRoleKeysList">
<cnsl-form-field class="form-field" appearance="outline">
<cnsl-label>{{ 'PROJECT.GRANT.ROLENAMESLIST' | translate }}</cnsl-label>
<mat-select multiple (selectionChange)="rolesList = $event.value">
<mat-option *ngFor="let role of grantedRoleKeysList" [value]="role">
{{role}}
</mat-option>
</mat-select>
</cnsl-form-field>
</ng-container>
</ng-container>
<cnsl-card>
<cnsl-project-roles-table
[displayedColumns]="['select', 'key', 'displayname', 'group', 'creationDate', 'changeDate']"
(changedSelection)="selectRoles($event)"
[projectId]="project?.id ? project.id : grantedProject?.projectId ? grantedProject.projectId : ''"
[grantId]="$any(project)?.grantId ? $any(project)?.grantId : ''">
</cnsl-project-roles-table>
</cnsl-card>
</ng-container>
<div class="btn-container">
<div class="btn-container">
<ng-container *ngIf="currentCreateStep === 1">
<button [disabled]="!org || !projectId || !userId" (click)="next()" color="primary" mat-raised-button
class="big-button" cdkFocusInitial>
{{ 'ACTIONS.CONTINUE' | translate }}
</button>
<button [disabled]="!org || !(project?.id || grantedProject?.projectId) || userIds.length < 1"
(click)="next()" color="primary" mat-raised-button class="big-button" cdkFocusInitial>
{{ 'ACTIONS.CONTINUE' | translate }}
</button>
</ng-container>
<ng-container *ngIf="currentCreateStep === STEPS">
<button (click)="previous()" color="primary" mat-button class="small-button" cdkFocusInitial>
{{ 'ACTIONS.BACK' | translate }}
</button>
<button color="primary" (click)="addGrant()" mat-raised-button class="big-button" cdkFocusInitial>
{{ 'ACTIONS.SAVE' | translate }}
</button>
<button (click)="previous()" mat-stroked-button class="small-button">
{{ 'ACTIONS.BACK' | translate }}
</button>
<button color="primary" (click)="addGrant()" mat-raised-button class="big-button" cdkFocusInitial>
{{ 'ACTIONS.SAVE' | translate }}
</button>
</ng-container>
</div>
</div>
</div>
</div>
@@ -1,64 +1,65 @@
.container {
padding: 4rem 4rem 2rem 4rem;
@media only screen and (max-width: 450px) {
padding: 4rem 1rem 2rem 1rem;
}
.abort-container {
display: flex;
align-items: center;
margin-bottom: 2rem;
.abort {
font-size: 1.2rem;
margin-left: 2rem;
}
.abort-2 {
font-size: 1.2rem;
margin-left: 2rem;
white-space: nowrap;
}
}
.desc {
color: var(--grey);
}
}
.block {
display: block;
}
.btn-container {
.abort-container {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 3rem;
margin-bottom: 2rem;
.small-button {
.abort {
font-size: 1.2rem;
margin-left: 2rem;
}
.abort-2 {
font-size: 1.2rem;
margin-left: 2rem;
white-space: nowrap;
}
}
.user-grant-create-content {
padding-left: 4.5rem;
.user-grant-create-desc {
max-width: 500px;
font-size: 14px;
}
.block {
display: block;
}
.big-button {
.btn-container {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 3rem;
.small-button {
display: block;
}
.big-button {
display: block;
padding: 0.5rem 4rem;
}
}
.sa-icon {
display: block;
padding: .5rem 4rem;
width: 32px;
margin: 0 0.5rem;
i {
margin: auto;
}
}
h2 {
margin-top: 2.5rem;
margin-bottom: 1rem;
font-size: 2rem;
&.project-search {
margin-bottom: 1.5rem;
}
}
}
.sa-icon {
display: block;
width: 32px;
margin: 0 .5rem;
i {
margin: auto;
}
}
h2 {
margin-top: 2.5rem;
margin-bottom: 1rem;
font-size: 2rem;
}
@@ -1,13 +1,14 @@
import { Location } from '@angular/common';
import { Component, OnDestroy } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Subscription } from 'rxjs';
import { Subject, takeUntil } from 'rxjs';
import { ProjectType } from 'src/app/modules/project-members/project-members-datasource';
import { UserTarget } from 'src/app/modules/search-user-autocomplete/search-user-autocomplete.component';
import { UserGrantContext } from 'src/app/modules/user-grants/user-grants-datasource';
import { Org } from 'src/app/proto/generated/zitadel/org_pb';
import { GrantedProject, Project, Role } from 'src/app/proto/generated/zitadel/project_pb';
import { User } from 'src/app/proto/generated/zitadel/user_pb';
import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
import { Breadcrumb, BreadcrumbService, BreadcrumbType } from 'src/app/services/breadcrumb.service';
import { ManagementService } from 'src/app/services/mgmt.service';
import { StorageKey, StorageLocation, StorageService } from 'src/app/services/storage.service';
import { ToastService } from 'src/app/services/toast.service';
@@ -21,76 +22,87 @@ export class UserGrantCreateComponent implements OnDestroy {
public context!: UserGrantContext;
public org!: Org.AsObject;
public userId: string = '';
public userIds: string[] = [];
public projectId: string = '';
public project!: GrantedProject.AsObject | Project.AsObject;
public project!: Project.AsObject;
public grantedProject!: GrantedProject.AsObject;
public grantId: string = '';
public rolesList: string[] = [];
public STEPS: number = 2; // project, roles
public currentCreateStep: number = 1;
public filterValue: string = '';
private subscription: Subscription = new Subscription();
public UserGrantContext: any = UserGrantContext;
public grantedRoleKeysList: string[] = [];
public user!: User.AsObject;
public UserTarget: any = UserTarget;
public editState: boolean = false;
private destroy$: Subject<void> = new Subject();
constructor(
private userService: ManagementService,
private toast: ToastService,
private _location: Location,
private route: ActivatedRoute,
private authService: GrpcAuthService,
private mgmtService: ManagementService,
private storage: StorageService,
breadcrumbService: BreadcrumbService,
) {
this.subscription = this.route.params.subscribe((params: Params) => {
breadcrumbService.setBreadcrumb([
new Breadcrumb({
type: BreadcrumbType.IAM,
name: 'IAM',
routerLink: ['/system'],
}),
new Breadcrumb({
type: BreadcrumbType.ORG,
routerLink: ['/org'],
}),
]);
this.route.params.pipe(takeUntil(this.destroy$)).subscribe((params: Params) => {
const { projectid, grantid, userid } = params;
this.context = UserGrantContext.NONE;
this.projectId = projectid;
this.grantId = grantid;
this.userId = userid;
this.userIds = userid ? [userid] : [];
if (this.projectId && !this.grantId) {
if (projectid && !grantid) {
this.context = UserGrantContext.OWNED_PROJECT;
this.mgmtService.getProjectByID(this.projectId).then(resp => {
if (resp.project) {
this.project = resp.project;
}
}).catch((error: any) => {
this.toast.showError(error);
});
} else if (this.projectId && this.grantId) {
this.mgmtService
.getProjectByID(projectid)
.then((resp) => {
if (resp.project) {
this.project = resp.project;
}
})
.catch((error: any) => {
this.toast.showError(error);
});
} else if (projectid && grantid) {
this.context = UserGrantContext.GRANTED_PROJECT;
this.mgmtService.getGrantedProjectByID(this.projectId, this.grantId).then(resp => {
if (resp.grantedProject) {
this.project = resp.grantedProject;
}
if (resp.grantedProject?.grantedRoleKeysList) {
this.grantedRoleKeysList = resp.grantedProject?.grantedRoleKeysList;
}
}).catch((error: any) => {
this.toast.showError(error);
});
} else if (this.userId) {
this.mgmtService
.getGrantedProjectByID(projectid, grantid)
.then((resp) => {
if (resp.grantedProject) {
this.grantedProject = resp.grantedProject;
}
})
.catch((error: any) => {
this.toast.showError(error);
});
} else if (this.userIds && this.userIds.length === 1) {
this.context = UserGrantContext.USER;
this.mgmtService.getUserByID(this.userId).then(resp => {
if (resp.user) {
this.user = resp.user;
}
}).catch((error: any) => {
this.toast.showError(error);
});
this.mgmtService
.getUserByID(this.userIds[0])
.then((resp) => {
if (resp.user) {
this.user = resp.user;
}
})
.catch((error: any) => {
this.toast.showError(error);
});
}
});
@@ -107,86 +119,95 @@ export class UserGrantCreateComponent implements OnDestroy {
public addGrant(): void {
switch (this.context) {
case UserGrantContext.OWNED_PROJECT:
this.userService.addUserGrant(
this.userId,
this.rolesList,
this.projectId,
).then(() => {
this.toast.showInfo('PROJECT.GRANT.TOAST.PROJECTGRANTADDED', true);
this.close();
}).catch((error: any) => {
this.toast.showError(error);
});
const prom = this.userIds.map((id) => this.userService.addUserGrant(id, this.rolesList, this.project.id));
Promise.all(prom)
.then(() => {
this.toast.showInfo('PROJECT.GRANT.TOAST.PROJECTGRANTADDED', true);
this.close();
})
.catch((error: any) => {
this.toast.showError(error);
this.close();
});
break;
case UserGrantContext.GRANTED_PROJECT:
this.userService.addUserGrant(
this.userId,
this.rolesList,
this.projectId,
this.grantId,
).then(() => {
this.toast.showInfo('PROJECT.GRANT.TOAST.PROJECTGRANTUSERGRANTADDED', true);
this.close();
}).catch((error: any) => {
this.toast.showError(error);
});
const promp = this.userIds.map((id) =>
this.userService.addUserGrant(id, this.rolesList, this.grantedProject.projectId, this.grantedProject.grantId),
);
Promise.all(promp)
.then(() => {
this.toast.showInfo('PROJECT.GRANT.TOAST.PROJECTGRANTUSERGRANTADDED', true);
this.close();
})
.catch((error: any) => {
this.toast.showError(error);
this.close();
});
break;
case UserGrantContext.USER:
let grantId;
let grantId: string = '';
if ((this.project as GrantedProject.AsObject)?.grantId) {
grantId = (this.project as GrantedProject.AsObject).grantId;
if (this.grantedProject?.grantId) {
grantId = this.grantedProject.grantId;
}
this.userService.addUserGrant(
this.userId,
this.rolesList,
this.projectId,
grantId,
).then(() => {
this.toast.showInfo('PROJECT.GRANT.TOAST.PROJECTGRANTUSERGRANTADDED', true);
this.close();
}).catch((error: any) => {
this.toast.showError(error);
});
const promu = this.userIds.map((id) =>
this.userService.addUserGrant(id, this.rolesList, (this.project as Project.AsObject).id, grantId),
);
Promise.all(promu)
.then(() => {
this.toast.showInfo('PROJECT.GRANT.TOAST.PROJECTGRANTUSERGRANTADDED', true);
this.close();
})
.catch((error: any) => {
this.toast.showError(error);
this.close();
});
break;
case UserGrantContext.NONE:
let tempGrantId;
let tempGrantId: string = '';
if ((this.project as GrantedProject.AsObject)?.grantId) {
tempGrantId = (this.project as GrantedProject.AsObject).grantId;
if (this.grantedProject?.grantId) {
tempGrantId = this.grantedProject.grantId;
}
this.userService.addUserGrant(
this.userId,
this.rolesList,
this.projectId,
tempGrantId,
).then(() => {
this.toast.showInfo('PROJECT.GRANT.TOAST.PROJECTGRANTUSERGRANTADDED', true);
this.close();
}).catch((error: any) => {
this.toast.showError(error);
});
const promn = this.userIds.map((id) =>
this.userService.addUserGrant(
id,
this.rolesList,
this.project ? this.project.id : this.grantedProject ? this.grantedProject.projectId : '',
tempGrantId,
),
);
Promise.all(promn)
.then(() => {
this.toast.showInfo('PROJECT.GRANT.TOAST.PROJECTGRANTUSERGRANTADDED', true);
this.close();
})
.catch((error: any) => {
this.toast.showError(error);
this.close();
});
break;
}
}
public selectProject(project: Project.AsObject | GrantedProject.AsObject | any): void {
this.project = project;
this.projectId = project.id || project.projectId;
this.grantedRoleKeysList = project.grantedRoleKeysList ?? [];
public selectProject(project: Project.AsObject | GrantedProject.AsObject, type: ProjectType): void {
if (type === ProjectType.PROJECTTYPE_OWNED) {
this.project = project as Project.AsObject;
} else if (type === ProjectType.PROJECTTYPE_GRANTED) {
this.grantedProject = project as GrantedProject.AsObject;
}
}
public selectUser(user: User.AsObject | User.AsObject[]): void {
if (typeof user === 'object') {
this.userId = (user as User.AsObject).id;
public selectUsers(user: User.AsObject[]): void {
if (user && user.length) {
this.userIds = (user as User.AsObject[]).map((u) => u.id);
}
}
public selectRoles(roles: Role.AsObject[]): void {
this.rolesList = roles.map(role => role.key);
this.rolesList = roles.map((role) => role.key);
}
public next(): void {
@@ -198,6 +219,7 @@ export class UserGrantCreateComponent implements OnDestroy {
}
public ngOnDestroy(): void {
this.subscription.unsubscribe();
this.destroy$.next();
this.destroy$.complete();
}
}
@@ -6,33 +6,31 @@ import { MatSelectModule } from '@angular/material/select';
import { TranslateModule } from '@ngx-translate/core';
import { CardModule } from 'src/app/modules/card/card.module';
import { InputModule } from 'src/app/modules/input/input.module';
import { ProjectRolesTableModule } from 'src/app/modules/project-roles-table/project-roles-table.module';
import {
SearchProjectAutocompleteModule,
SearchProjectAutocompleteModule,
} from 'src/app/modules/search-project-autocomplete/search-project-autocomplete.module';
import { SearchUserAutocompleteModule } from 'src/app/modules/search-user-autocomplete/search-user-autocomplete.module';
import { SharedModule } from 'src/app/modules/shared/shared.module';
import { ProjectRolesModule } from '../../modules/project-roles/project-roles.module';
import { UserGrantCreateRoutingModule } from './user-grant-create-routing.module';
import { UserGrantCreateComponent } from './user-grant-create.component';
@NgModule({
declarations: [UserGrantCreateComponent],
imports: [
UserGrantCreateRoutingModule,
CommonModule,
MatButtonModule,
MatIconModule,
TranslateModule,
CardModule,
InputModule,
MatSelectModule,
SearchProjectAutocompleteModule,
SearchUserAutocompleteModule,
ProjectRolesModule,
SharedModule,
],
declarations: [UserGrantCreateComponent],
imports: [
UserGrantCreateRoutingModule,
CommonModule,
MatButtonModule,
MatIconModule,
TranslateModule,
CardModule,
InputModule,
MatSelectModule,
SearchProjectAutocompleteModule,
SearchUserAutocompleteModule,
ProjectRolesTableModule,
SharedModule,
],
})
export class UserGrantCreateModule { }
export class UserGrantCreateModule {}