Browse Source

Improve user account deletion flow

pull/7269/head
Thomas Kaul 1 week ago
parent
commit
70ebf23d9e
  1. 21
      apps/client/src/app/components/user-account-settings/user-account-settings.component.ts
  2. 118
      apps/client/src/app/components/user-account-settings/user-account-settings.html

21
apps/client/src/app/components/user-account-settings/user-account-settings.component.ts

@ -1,3 +1,4 @@
import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service';
import {
KEY_STAY_SIGNED_IN,
KEY_TOKEN,
@ -76,6 +77,8 @@ export class GfUserAccountSettingsComponent implements OnInit {
public deleteOwnUserForm = this.formBuilder.group({
accessToken: ['', Validators.required]
});
public hasImpersonationId: boolean;
public hasPermissionForSubscription: boolean;
public hasPermissionToDeleteOwnUser: boolean;
public hasPermissionToUpdateViewMode: boolean;
public hasPermissionToUpdateUserSettings: boolean;
@ -108,17 +111,33 @@ export class GfUserAccountSettingsComponent implements OnInit {
private dataService: DataService,
private destroyRef: DestroyRef,
private formBuilder: FormBuilder,
private impersonationStorageService: ImpersonationStorageService,
private notificationService: NotificationService,
private settingsStorageService: SettingsStorageService,
private snackBar: MatSnackBar,
private userService: UserService,
public webAuthnService: WebAuthnService
) {
const { baseCurrency, currencies } = this.dataService.fetchInfo();
const { baseCurrency, currencies, globalPermissions } =
this.dataService.fetchInfo();
this.baseCurrency = baseCurrency;
this.currencies = currencies;
this.hasPermissionForSubscription = hasPermission(
globalPermissions,
permissions.enableSubscription
);
this.impersonationStorageService
.onChangeHasImpersonation()
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((impersonationId) => {
this.hasImpersonationId = !!impersonationId;
this.changeDetectorRef.markForCheck();
});
this.userService.stateChanged
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((state) => {

118
apps/client/src/app/components/user-account-settings/user-account-settings.html

@ -285,67 +285,75 @@
</button>
</div>
</div>
<hr class="mt-5" />
<div class="d-flex py-1">
<div class="pr-1 text-danger w-50" i18n>Danger Zone</div>
<div class="pl-1 w-50">
@if (hasPermissionToDeleteOwnUser) {
<form
class="w-100"
[formGroup]="deleteOwnUserForm"
(ngSubmit)="onCloseAccount()"
>
<mat-form-field
appearance="outline"
class="without-hint w-100"
[hideRequiredMarker]="true"
@if (
!hasImpersonationId &&
(hasPermissionToDeleteOwnUser || hasPermissionForSubscription)
) {
<hr class="mt-5" />
<div class="d-flex py-1">
<div class="pr-1 text-danger w-50" i18n>Danger Zone</div>
<div class="pl-1 w-50">
@if (hasPermissionToDeleteOwnUser) {
<form
class="w-100"
[formGroup]="deleteOwnUserForm"
(ngSubmit)="onCloseAccount()"
>
<mat-label i18n>Security Token</mat-label>
<input
formControlName="accessToken"
matInput
[type]="isAccessTokenHidden ? 'password' : 'text'"
/>
<button
class="mx-2"
mat-icon-button
matSuffix
type="button"
(click)="isAccessTokenHidden = !isAccessTokenHidden"
<mat-form-field
appearance="outline"
class="without-hint w-100"
[hideRequiredMarker]="true"
>
<ion-icon
class="mat-icon"
[name]="
isAccessTokenHidden ? 'eye-outline' : 'eye-off-outline'
"
<mat-label i18n>Security Token</mat-label>
<input
formControlName="accessToken"
matInput
[type]="isAccessTokenHidden ? 'password' : 'text'"
/>
<button
class="mx-2"
mat-icon-button
matSuffix
type="button"
(click)="isAccessTokenHidden = !isAccessTokenHidden"
>
<ion-icon
class="mat-icon"
[name]="
isAccessTokenHidden ? 'eye-outline' : 'eye-off-outline'
"
/>
</button>
</mat-form-field>
<button
class="mt-2"
color="warn"
i18n
mat-flat-button
type="submit"
[disabled]="
!(deleteOwnUserForm.dirty && deleteOwnUserForm.valid)
"
>
Close Account
</button>
</mat-form-field>
<button
class="mt-2"
color="warn"
i18n
mat-flat-button
type="submit"
[disabled]="
!(deleteOwnUserForm.dirty && deleteOwnUserForm.valid)
"
</form>
} @else if (
hasPermissionForSubscription &&
(user?.accounts?.length > 0 || user?.activitiesCount > 0)
) {
<div class="hint-text text-muted" i18n>
For security reasons, please delete all activities and accounts
first before your Ghostfolio account can be closed.
</div>
} @else if (hasPermissionForSubscription) {
<a color="warn" i18n mat-flat-button [href]="closeUserAccountMail"
>Close Account</a
>
Close Account
</button>
</form>
} @else if (user?.accounts?.length > 0 || user?.activitiesCount > 0) {
<div class="hint-text text-muted" i18n>
For security reasons, please delete all activities and accounts
first before your Ghostfolio account can be closed.
</div>
} @else {
<a color="warn" i18n mat-flat-button [href]="closeUserAccountMail"
>Close Account</a
>
}
}
</div>
</div>
</div>
}
</div>
</div>
</div>

Loading…
Cancel
Save