Browse Source

Migrate account dialogs to dedicated routes

pull/7473/head
Thomas Kaul 1 month ago
parent
commit
a82332117d
  1. 37
      apps/client/src/app/pages/accounts/account-dialog-host/account-dialog-host.component.ts

37
apps/client/src/app/pages/accounts/account-dialog-host/account-dialog-host.component.ts

@ -110,23 +110,16 @@ export class GfAccountDialogHostComponent implements OnDestroy, OnInit {
if (mode === 'update') { if (mode === 'update') {
if ( if (
!account || !account ||
!hasPermission(user?.permissions, permissions.updateAccount) !hasPermission(user?.permissions, permissions.updateAccount) ||
this.isReadOnlyMode(user)
) { ) {
this.navigateBack(); this.navigateBack();
return; return;
} }
const { const { balance, comment, currency, id, name, platformId, tags } =
balance, account;
comment,
currency,
id,
isExcluded,
name,
platformId,
tags
} = account;
this.openCreateOrUpdateAccountDialog({ this.openCreateOrUpdateAccountDialog({
user, user,
@ -135,7 +128,6 @@ export class GfAccountDialogHostComponent implements OnDestroy, OnInit {
comment, comment,
currency, currency,
id, id,
isExcluded,
name, name,
platformId, platformId,
tags tags
@ -146,7 +138,10 @@ export class GfAccountDialogHostComponent implements OnDestroy, OnInit {
return; return;
} }
if (!hasPermission(user?.permissions, permissions.createAccount)) { if (
!hasPermission(user?.permissions, permissions.createAccount) ||
this.isReadOnlyMode(user)
) {
this.navigateBack(); this.navigateBack();
return; return;
@ -159,7 +154,6 @@ export class GfAccountDialogHostComponent implements OnDestroy, OnInit {
comment: null, comment: null,
currency: user?.settings?.baseCurrency ?? null, currency: user?.settings?.baseCurrency ?? null,
id: null, id: null,
isExcluded: false,
name: null, name: null,
platformId: null, platformId: null,
tags: [] tags: []
@ -187,6 +181,15 @@ export class GfAccountDialogHostComponent implements OnDestroy, OnInit {
this.dialogRef?.close(); this.dialogRef?.close();
} }
private isReadOnlyMode(user: User) {
// Mirrors the conditions under which the accounts page offers the creation
// and the modification of an account
return (
!!this.impersonationStorageService.getId() ||
!!user?.settings?.isRestrictedView
);
}
private navigateBack() { private navigateBack() {
void this.router.navigate(internalRoutes.accounts.routerLink); void this.router.navigate(internalRoutes.accounts.routerLink);
} }
@ -204,7 +207,7 @@ export class GfAccountDialogHostComponent implements OnDestroy, OnInit {
return; return;
} }
const hasImpersonationId = !!this.impersonationStorageService.getId(); const impersonationId = this.impersonationStorageService.getId();
const dialogRef = this.dialog.open< const dialogRef = this.dialog.open<
GfAccountDetailDialogComponent, GfAccountDetailDialogComponent,
@ -214,10 +217,10 @@ export class GfAccountDialogHostComponent implements OnDestroy, OnInit {
autoFocus: false, autoFocus: false,
data: { data: {
accountId, accountId,
hasImpersonationId, impersonationId,
deviceType: this.deviceType(), deviceType: this.deviceType(),
hasPermissionToCreateActivity: hasPermissionToCreateActivity:
!hasImpersonationId && !impersonationId &&
hasPermission(user?.permissions, permissions.createActivity) && hasPermission(user?.permissions, permissions.createActivity) &&
!user?.settings?.isRestrictedView !user?.settings?.isRestrictedView
}, },

Loading…
Cancel
Save