feat(console): machine user accesstoken type (#5196)

Set machine user Access Token type
This commit is contained in:
Max Peintner
2023-02-14 17:05:55 +01:00
committed by GitHub
parent 3696c1b2d9
commit df4a173264
14 changed files with 83 additions and 13 deletions

View File

@@ -30,6 +30,15 @@
<cnsl-label>{{ 'USER.MACHINE.DESCRIPTION' | translate }}</cnsl-label>
<input cnslInput formControlName="description" />
</cnsl-form-field>
<cnsl-form-field class="formfield">
<cnsl-label>{{ 'USER.MACHINE.ACCESSTOKENTYPE' | translate }}</cnsl-label>
<mat-select formControlName="accessTokenType" required>
<mat-option *ngFor="let aTT of accessTokenTypes" [value]="aTT">
{{ 'USER.MACHINE.ACCESSTOKENTYPES.' + aTT | translate }}
</mat-option>
</mat-select>
</cnsl-form-field>
</div>
<div class="machine-btn-container">
<button color="primary" data-e2e="create-button" [disabled]="userForm.invalid" type="submit" mat-raised-button>

View File

@@ -4,6 +4,7 @@ import { AbstractControl, UntypedFormBuilder, UntypedFormGroup, Validators } fro
import { Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { AddMachineUserRequest } from 'src/app/proto/generated/zitadel/management_pb';
import { AccessTokenType } from 'src/app/proto/generated/zitadel/user_pb';
import { Breadcrumb, BreadcrumbService, BreadcrumbType } from 'src/app/services/breadcrumb.service';
import { ManagementService } from 'src/app/services/mgmt.service';
import { ToastService } from 'src/app/services/toast.service';
@@ -20,6 +21,11 @@ export class UserCreateMachineComponent implements OnDestroy {
private sub: Subscription = new Subscription();
public loading: boolean = false;
public accessTokenTypes: AccessTokenType[] = [
AccessTokenType.ACCESS_TOKEN_TYPE_BEARER,
AccessTokenType.ACCESS_TOKEN_TYPE_JWT,
];
constructor(
private router: Router,
private toast: ToastService,
@@ -42,6 +48,7 @@ export class UserCreateMachineComponent implements OnDestroy {
userName: ['', [Validators.required, Validators.minLength(2)]],
name: ['', [Validators.required]],
description: ['', []],
accessTokenType: [AccessTokenType.ACCESS_TOKEN_TYPE_BEARER, []],
});
}
@@ -54,6 +61,7 @@ export class UserCreateMachineComponent implements OnDestroy {
machineReq.setDescription(this.description?.value);
machineReq.setName(this.name?.value);
machineReq.setUserName(this.userName?.value);
machineReq.setAccessTokenType(this.accessTokenType?.value);
this.userService
.addMachineUser(machineReq)
@@ -88,4 +96,7 @@ export class UserCreateMachineComponent implements OnDestroy {
public get userName(): AbstractControl | null {
return this.userForm.get('userName');
}
public get accessTokenType(): AbstractControl | null {
return this.userForm.get('accessTokenType');
}
}

View File

@@ -21,6 +21,14 @@
<cnsl-label>{{ 'USER.MACHINE.DESCRIPTION' | translate }}</cnsl-label>
<input cnslInput formControlName="description" />
</cnsl-form-field>
<cnsl-form-field class="formfield">
<cnsl-label>{{ 'USER.MACHINE.ACCESSTOKENTYPE' | translate }}</cnsl-label>
<mat-select formControlName="accessTokenType" required>
<mat-option *ngFor="let aTT of accessTokenTypes" [value]="aTT">
{{ 'USER.MACHINE.ACCESSTOKENTYPES.' + aTT | translate }}
</mat-option>
</mat-select>
</cnsl-form-field>
</div>
<div class="btn-container">
<button type="submit" color="primary" mat-raised-button>{{ 'ACTIONS.SAVE' | translate }}</button>

View File

@@ -1,7 +1,7 @@
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { AbstractControl, UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { Subscription } from 'rxjs';
import { Human, Machine } from 'src/app/proto/generated/zitadel/user_pb';
import { AccessTokenType, Human, Machine } from 'src/app/proto/generated/zitadel/user_pb';
@Component({
selector: 'cnsl-detail-form-machine',
@@ -16,6 +16,11 @@ export class DetailFormMachineComponent implements OnInit, OnDestroy {
public machineForm!: UntypedFormGroup;
public accessTokenTypes: AccessTokenType[] = [
AccessTokenType.ACCESS_TOKEN_TYPE_BEARER,
AccessTokenType.ACCESS_TOKEN_TYPE_JWT,
];
private sub: Subscription = new Subscription();
constructor(private fb: UntypedFormBuilder) {
@@ -23,6 +28,7 @@ export class DetailFormMachineComponent implements OnInit, OnDestroy {
userName: [{ value: '', disabled: true }, [Validators.required]],
name: [{ value: '', disabled: this.disabled }, Validators.required],
description: [{ value: '', disabled: this.disabled }],
accessTokenType: [AccessTokenType.ACCESS_TOKEN_TYPE_BEARER, [Validators.required]],
});
}
@@ -42,10 +48,6 @@ export class DetailFormMachineComponent implements OnInit, OnDestroy {
return this.machineForm.get('name');
}
public get description(): AbstractControl | null {
return this.machineForm.get('description');
}
public get userName(): AbstractControl | null {
return this.machineForm.get('userName');
}

View File

@@ -274,9 +274,15 @@ export class UserDetailComponent implements OnInit {
if (this.user.machine) {
this.user.machine.name = machineData.name;
this.user.machine.description = machineData.description;
this.user.machine.accessTokenType = machineData.accessTokenType;
this.mgmtUserService
.updateMachine(this.user.id, this.user.machine.name, this.user.machine.description)
.updateMachine(
this.user.id,
this.user.machine.name,
this.user.machine.description,
this.user.machine.accessTokenType,
)
.then(() => {
this.toast.showInfo('USER.TOAST.SAVED', true);
this.refreshChanges$.emit();