Files
zitadel/console/src/app/pages/user-grant-create/user-grant-create.component.ts
T
9c07711aab fix(console): project member grants, user grants (#329)
* checkbox color

* project grant preview

* project grante expandable row

* add grant detail component

* proto regen

* project grant members shared module

* fix project grant members dialog

* fix create dialog

* lint

* add avatar colors, meta component styling

* light theme

* dl report

* styles

* move grants out of user context, grant detail

* i18n grant pipe

* lint

* user grants

* clear expandable view project grants

* fix project member routing

* fix granted members routing

* fix group label

* rename project grant

* disable zitadel grant members

* fix routing user grant creation

* rest member writes

* ignore case searches

* forkjoin observables for project search

* fix grant creation with users

* fix projectid reference

* formfield table style, user grant dynamic load

* show key if no displayvalue is set

* Delete report.20200630.163913.44081.0.001.json

Co-authored-by: Silvan <[email protected]>
2020-07-01 17:48:34 +02:00

109 lines
3.2 KiB
TypeScript

import { Location } from '@angular/common';
import { Component, OnDestroy } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Subscription } from 'rxjs';
import { Org } from 'src/app/proto/generated/auth_pb';
import {
ProjectGrantView,
ProjectRole,
ProjectView,
User,
UserGrant,
UserGrantSearchKey,
} from 'src/app/proto/generated/management_pb';
import { AuthService } from 'src/app/services/auth.service';
import { MgmtUserService } from 'src/app/services/mgmt-user.service';
import { ToastService } from 'src/app/services/toast.service';
@Component({
selector: 'app-user-grant-create',
templateUrl: './user-grant-create.component.html',
styleUrls: ['./user-grant-create.component.scss'],
})
export class UserGrantCreateComponent implements OnDestroy {
public org!: Org.AsObject;
public userId: string = '';
public projectId: string = '';
public grantId: string = '';
public rolesList: string[] = [];
public STEPS: number = 2; // project, roles
public currentCreateStep: number = 1;
public filter!: UserGrantSearchKey;
public filterValue: string = '';
private subscription: Subscription = new Subscription();
public UserGrantSearchKey: any = UserGrantSearchKey;
constructor(
private authService: AuthService,
private userService: MgmtUserService,
private toast: ToastService,
private _location: Location,
private route: ActivatedRoute,
) {
this.subscription = this.route.params.subscribe((params: Params) => {
console.log(params);
const { filter, filterValue } = params;
this.filter = filter;
switch (filter) {
case (`${UserGrantSearchKey.USERGRANTSEARCHKEY_PROJECT_ID}`):
this.projectId = filterValue;
break;
case (`${UserGrantSearchKey.USERGRANTSEARCHKEY_USER_ID}`):
this.userId = filterValue;
break;
}
console.log(this.projectId, this.userId);
});
this.authService.GetActiveOrg().then(org => {
this.org = org;
});
}
public close(): void {
this._location.back();
}
public addGrant(): void {
this.userService.CreateUserGrant(
this.projectId,
this.userId,
this.rolesList,
).then((data: UserGrant) => {
this.close();
}).catch(error => {
this.toast.showError(error.message);
});
}
public selectProject(project: ProjectView.AsObject | ProjectGrantView.AsObject | any): void {
console.log(project);
this.projectId = project.projectId;
}
public selectUser(user: User.AsObject): void {
console.log(user);
this.userId = user.id;
}
public selectRoles(roles: ProjectRole.AsObject[]): void {
this.rolesList = roles.map(role => role.key);
}
public next(): void {
this.currentCreateStep++;
}
public previous(): void {
this.currentCreateStep--;
}
public ngOnDestroy(): void {
this.subscription.unsubscribe();
}
}