@ -1,4 +1,5 @@
import { GfAccessTableComponent } from '@ghostfolio/client/components/access-table/access-table.component' ;
import { GfAccessTableComponent } from '@ghostfolio/client/components/access-table/access-table.component' ;
import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service' ;
import { UserService } from '@ghostfolio/client/services/user/user.service' ;
import { UserService } from '@ghostfolio/client/services/user/user.service' ;
import { CreateAccessDto } from '@ghostfolio/common/dtos' ;
import { CreateAccessDto } from '@ghostfolio/common/dtos' ;
import { ConfirmationDialogType } from '@ghostfolio/common/enums' ;
import { ConfirmationDialogType } from '@ghostfolio/common/enums' ;
@ -36,7 +37,7 @@ import { addIcons } from 'ionicons';
import { addOutline , eyeOffOutline , eyeOutline } from 'ionicons/icons' ;
import { addOutline , eyeOffOutline , eyeOutline } from 'ionicons/icons' ;
import { DeviceDetectorService } from 'ngx-device-detector' ;
import { DeviceDetectorService } from 'ngx-device-detector' ;
import { EMPTY } from 'rxjs' ;
import { EMPTY } from 'rxjs' ;
import { catchError } from 'rxjs/operators' ;
import { catchError , switchMap } from 'rxjs/operators' ;
import { GfCreateOrUpdateAccessDialogComponent } from './create-or-update-access-dialog/create-or-update-access-dialog.component' ;
import { GfCreateOrUpdateAccessDialogComponent } from './create-or-update-access-dialog/create-or-update-access-dialog.component' ;
import { CreateOrUpdateAccessDialogParams } from './create-or-update-access-dialog/interfaces/interfaces' ;
import { CreateOrUpdateAccessDialogParams } from './create-or-update-access-dialog/interfaces/interfaces' ;
@ -63,6 +64,7 @@ import { CreateOrUpdateAccessDialogParams } from './create-or-update-access-dial
export class GfUserAccountAccessComponent implements OnInit {
export class GfUserAccountAccessComponent implements OnInit {
protected accessesGet : Access [ ] ;
protected accessesGet : Access [ ] ;
protected accessesGive : Access [ ] ;
protected accessesGive : Access [ ] ;
protected hasImpersonationId : boolean ;
protected hasPermissionToCreateAccess : boolean ;
protected hasPermissionToCreateAccess : boolean ;
protected hasPermissionToDeleteAccess : boolean ;
protected hasPermissionToDeleteAccess : boolean ;
protected hasPermissionToUpdateOwnAccessToken : boolean ;
protected hasPermissionToUpdateOwnAccessToken : boolean ;
@ -84,6 +86,9 @@ export class GfUserAccountAccessComponent implements OnInit {
private readonly destroyRef = inject ( DestroyRef ) ;
private readonly destroyRef = inject ( DestroyRef ) ;
private readonly deviceDetectorService = inject ( DeviceDetectorService ) ;
private readonly deviceDetectorService = inject ( DeviceDetectorService ) ;
private readonly dialog = inject ( MatDialog ) ;
private readonly dialog = inject ( MatDialog ) ;
private readonly impersonationStorageService = inject (
ImpersonationStorageService
) ;
private readonly notificationService = inject ( NotificationService ) ;
private readonly notificationService = inject ( NotificationService ) ;
private readonly route = inject ( ActivatedRoute ) ;
private readonly route = inject ( ActivatedRoute ) ;
private readonly router = inject ( Router ) ;
private readonly router = inject ( Router ) ;
@ -97,6 +102,15 @@ export class GfUserAccountAccessComponent implements OnInit {
permissions . deleteAccess
permissions . deleteAccess
) ;
) ;
this . impersonationStorageService
. onChangeHasImpersonation ( )
. pipe ( takeUntilDestroyed ( this . destroyRef ) )
. subscribe ( ( impersonationId ) = > {
this . hasImpersonationId = ! ! impersonationId ;
this . changeDetectorRef . markForCheck ( ) ;
} ) ;
this . userService . stateChanged
this . userService . stateChanged
. pipe ( takeUntilDestroyed ( this . destroyRef ) )
. pipe ( takeUntilDestroyed ( this . destroyRef ) )
. subscribe ( ( state ) = > {
. subscribe ( ( state ) = > {
@ -142,11 +156,39 @@ export class GfUserAccountAccessComponent implements OnInit {
protected onDeleteAccess ( aId : string ) {
protected onDeleteAccess ( aId : string ) {
this . dataService
this . dataService
. deleteAccess ( aId )
. deleteAccess ( aId )
. pipe ( takeUntilDestroyed ( this . destroyRef ) )
. pipe (
. subscribe ( {
catchError ( ( ) = > {
next : ( ) = > {
this . notificationService . alert ( {
this . update ( ) ;
title : $localize ` Oops! Could not revoke the granted access. `
}
} ) ;
return EMPTY ;
} ) ,
takeUntilDestroyed ( this . destroyRef )
)
. subscribe ( ( ) = > {
this . update ( ) ;
} ) ;
}
protected onDeleteReceivedAccess ( aId : string ) {
this . dataService
. deleteAccess ( aId )
. pipe (
switchMap ( ( ) = > {
return this . userService . get ( true ) ;
} ) ,
catchError ( ( ) = > {
this . notificationService . alert ( {
title : $localize ` Oops! Could not remove the received access. `
} ) ;
return EMPTY ;
} ) ,
takeUntilDestroyed ( this . destroyRef )
)
. subscribe ( ( ) = > {
this . update ( ) ;
} ) ;
} ) ;
}
}