From af3c3d4c661d25e1a180b6d1b4416456801f4522 Mon Sep 17 00:00:00 2001 From: conblem Date: Thu, 27 Feb 2025 15:39:26 +0100 Subject: [PATCH] fix: load using auth service --- .../auth-user-detail.component.ts | 42 ++++--------------- console/src/app/services/new-auth.service.ts | 15 +++---- 2 files changed, 15 insertions(+), 42 deletions(-) diff --git a/console/src/app/pages/users/user-detail/auth-user-detail/auth-user-detail.component.ts b/console/src/app/pages/users/user-detail/auth-user-detail/auth-user-detail.component.ts index 7016360352..2752dd9265 100644 --- a/console/src/app/pages/users/user-detail/auth-user-detail/auth-user-detail.component.ts +++ b/console/src/app/pages/users/user-detail/auth-user-detail/auth-user-detail.component.ts @@ -5,19 +5,7 @@ import { MatDialog } from '@angular/material/dialog'; import { ActivatedRoute, Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; import { Buffer } from 'buffer'; -import { - combineLatestWith, - defer, - EMPTY, - fromEvent, - mergeWith, - Observable, - of, - shareReplay, - Subject, - switchMap, - take, -} from 'rxjs'; +import { defer, EMPTY, fromEvent, mergeWith, Observable, of, shareReplay, Subject, switchMap, take } from 'rxjs'; import { ChangeType } from 'src/app/modules/changes/changes.component'; import { phoneValidator, requiredValidator } from 'src/app/modules/form-field/validators/validators'; import { InfoDialogComponent } from 'src/app/modules/info-dialog/info-dialog.component'; @@ -37,7 +25,7 @@ import { formatPhone } from 'src/app/utils/formatPhone'; import { EditDialogComponent, EditDialogData, EditDialogResult, EditDialogType } from './edit-dialog/edit-dialog.component'; import { LanguagesService } from 'src/app/services/languages.service'; import { Gender, HumanProfile, HumanUser, User, UserState } from '@zitadel/proto/zitadel/user/v2/user_pb'; -import { catchError, filter, map, startWith, tap, withLatestFrom } from 'rxjs/operators'; +import { catchError, filter, map, startWith, withLatestFrom } from 'rxjs/operators'; import { pairwiseStartWith } from 'src/app/utils/pairwiseStartWith'; import { NewAuthService } from 'src/app/services/new-auth.service'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; @@ -46,7 +34,6 @@ import { Metadata } from '@zitadel/proto/zitadel/metadata_pb'; import { UserService } from 'src/app/services/user.service'; import { LoginPolicy } from '@zitadel/proto/zitadel/policy_pb'; import { query } from '@angular/animations'; -import { withLatestFromSynchronousFix } from '../../../../utils/withLatestFromSynchronousFix'; type UserQuery = { state: 'success'; value: User } | { state: 'error'; error: any } | { state: 'loading'; value?: User }; @@ -112,7 +99,7 @@ export class AuthUserDetailComponent implements OnInit { this.user$ = this.getUser$().pipe(shareReplay({ refCount: true, bufferSize: 1 })); this.userName$ = this.getUserName(this.user$); this.savedLanguage$ = this.getSavedLanguage$(this.user$); - this.metadata$ = this.getMetadata$(this.user$).pipe(shareReplay({ refCount: true, bufferSize: 1 })); + this.metadata$ = this.getMetadata$().pipe(shareReplay({ refCount: true, bufferSize: 1 })); this.loginPolicy$ = defer(() => this.newMgmtService.getLoginPolicy()).pipe( catchError(() => EMPTY), @@ -212,25 +199,10 @@ export class AuthUserDetailComponent implements OnInit { ); } - getMetadata$(user$: Observable): Observable { - const isAllowed$ = this.grpcAuthService.isAllowed(['user.read']); - + getMetadata$(): Observable { return this.refreshMetadata$.pipe( startWith(true), - combineLatestWith(user$), - withLatestFromSynchronousFix(isAllowed$), - switchMap(([[_, user], isAllowed]): Observable => { - if (!isAllowed) { - return of({ state: 'success', value: [] }); - } - if (!(user.state === 'success' || user.state === 'loading')) { - return EMPTY; - } - if (!user.value) { - return EMPTY; - } - return this.getMetadataById(user.value.userId); - }), + switchMap(() => this.getMetadata()), pairwiseStartWith(undefined), map(([prev, curr]) => { if (prev?.state === 'success' && curr.state === 'loading') { @@ -241,8 +213,8 @@ export class AuthUserDetailComponent implements OnInit { ); } - private getMetadataById(userId: string): Observable { - return defer(() => this.newMgmtService.listUserMetadata(userId)).pipe( + private getMetadata(): Observable { + return defer(() => this.newAuthService.listMyMetadata()).pipe( map((metadata) => ({ state: 'success', value: metadata.result }) as const), startWith({ state: 'loading', value: [] as Metadata[] } as const), catchError((error) => of({ state: 'error', error } as const)), diff --git a/console/src/app/services/new-auth.service.ts b/console/src/app/services/new-auth.service.ts index 3e09ea7ad4..34b12bb90f 100644 --- a/console/src/app/services/new-auth.service.ts +++ b/console/src/app/services/new-auth.service.ts @@ -1,12 +1,9 @@ import { Injectable } from '@angular/core'; import { GrpcService } from './grpc.service'; -import { create } from '@bufbuild/protobuf'; import { - AddMyAuthFactorOTPSMSRequestSchema, AddMyAuthFactorOTPSMSResponse, - GetMyUserRequestSchema, GetMyUserResponse, - VerifyMyPhoneRequestSchema, + ListMyMetadataResponse, VerifyMyPhoneResponse, } from '@zitadel/proto/zitadel/auth_pb'; @@ -17,14 +14,18 @@ export class NewAuthService { constructor(private readonly grpcService: GrpcService) {} public getMyUser(): Promise { - return this.grpcService.authNew.getMyUser(create(GetMyUserRequestSchema)); + return this.grpcService.authNew.getMyUser({}); } public verifyMyPhone(code: string): Promise { - return this.grpcService.authNew.verifyMyPhone(create(VerifyMyPhoneRequestSchema, { code })); + return this.grpcService.authNew.verifyMyPhone({}); } public addMyAuthFactorOTPSMS(): Promise { - return this.grpcService.authNew.addMyAuthFactorOTPSMS(create(AddMyAuthFactorOTPSMSRequestSchema)); + return this.grpcService.authNew.addMyAuthFactorOTPSMS({}); + } + + public listMyMetadata(): Promise { + return this.grpcService.authNew.listMyMetadata({}); } }