fix(frontend/accounts): unfucked everything

This commit is contained in:
Mats Paul Tončik
2026-07-04 23:49:39 +02:00
29 changed files with 676 additions and 294 deletions
@@ -16,22 +16,38 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import type {
AccountPayload,
import {
AccountProfile,
AccountRole,
CreateAccountPayload,
OrganizationProfile,
} from '../../shared/services/account-management.service';
InseAccountManagementModelOrganizationProfile,
UserRole,
} from '../../api';
export type AccountDialogMode = 'create' | 'edit';
export interface AccountDialogData {
mode: AccountDialogMode;
account?: AccountProfile;
organizations: OrganizationProfile[];
organizations: InseAccountManagementModelOrganizationProfile[];
canSelectOrganization: boolean;
roles: AccountRole[];
roles: UserRole[];
}
export interface AccountPayload {
email?: string;
name?: string;
role?: UserRole;
organization_id?: string;
password?: string;
deleted?: boolean;
activated?: boolean;
}
export interface CreateAccountPayload {
email: string;
name: string;
role: UserRole;
organization_id: string;
password: string;
}
export type AccountDialogResult =
@@ -69,7 +85,7 @@ export class AccountDialogComponent {
name: new FormControl<string>(this.data.account?.name ?? '', [
Validators.required,
]),
role: new FormControl<AccountRole>(this.data.account?.role ?? 'USER', [
role: new FormControl<UserRole>(this.data.account?.role ?? 'USER', [
Validators.required,
]),
organizationId: new FormControl<string>(
@@ -148,6 +164,6 @@ export class AccountDialogComponent {
}
protected close(): void {
this.dialogRef.close(undefined);
this.dialogRef.close();
}
}
@@ -2,34 +2,39 @@
<header class="page-header">
<div>
<h1>Accounts</h1>
<p>Account-Zugänge verwalten, Rollen setzen und Impersonation starten.</p>
<p>
{{
isReadOnly
? 'Personen der eigenen Organisation ansehen.'
: 'Account-Zugänge verwalten, Rollen setzen und Impersonation starten.'
}}
</p>
</div>
<button
mat-flat-button
color="primary"
type="button"
(click)="startCreate()">
<mat-icon>person_add</mat-icon>
Neuer Account
</button>
@if (!isReadOnly) {
<button
mat-flat-button
color="primary"
type="button"
matTooltip="Neuen Account anlegen"
(click)="startCreate()">
<mat-icon>person_add</mat-icon>
Neuer Account
</button>
}
</header>
<div
style="
display: flex;
gap: 1rem;
align-items: center;
justify-content: space-between;
">
<section style="display: flex; gap: 1rem; align-items: center">
<app-query-param-input
queryParamKey="search"
label="Nach Name oder E-Mail suchen"
style="width: 30%" />
style="width: 35%" />
<app-query-param-selector
queryParamKey="organization_id"
[options]="selectorOptions"
label="Organisation" />
</div>
[options]="selectorOptions()"
label="Organisation"
[allowEmptyValue]="true"
style="width: 25%" />
</section>
<mat-card appearance="outlined">
<mat-card-content>
<app-data-table [columns]="accountColumns" [data]="accountPage().items" />
@@ -43,8 +48,13 @@
</ng-template>
<ng-template #accountStatusTmp let-row>
<span class="status" [class.status--deleted]="row.deleted">
{{ row.deleted ? 'deleted' : 'active' }}
<span
class="status"
[class.status--deleted]="row.deleted"
[class.status--deactivated]="!row.deleted && !row.activated">
{{
(row.deleted ? 'deleted' : row.activated ? 'active' : 'inactive') | status
}}
</span>
</ng-template>
@@ -65,6 +75,14 @@
(click)="impersonate(row)">
<mat-icon>switch_account</mat-icon>
</button>
<button
mat-icon-button
type="button"
[attr.aria-label]="row.activated ? 'Deaktivieren' : 'Aktivieren'"
[disabled]="row.is_current || row.deleted"
(click)="toggleAccountActivation(row)">
<mat-icon>{{ row.activated ? 'person_off' : 'person_check' }}</mat-icon>
</button>
<button
mat-icon-button
type="button"
@@ -88,6 +88,11 @@ tr.deleted {
color: #94a3b8;
}
tr.deactivated:not(.deleted) {
color: #64748b;
background: #f8fafc;
}
.link-button {
border: 0;
background: transparent;
@@ -120,6 +125,11 @@ tr.deleted {
color: #991b1b;
}
.status--deactivated {
background: #fef3c7;
color: #92400e;
}
.row-actions {
gap: 4px;
}
@@ -3,26 +3,22 @@ import {
Component,
OnInit,
TemplateRef,
effect,
computed,
inject,
input,
viewChild,
} from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
import { MatTooltipModule } from '@angular/material/tooltip';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { Router } from '@angular/router';
import { finalize } from 'rxjs';
import {
AccountManagementService,
AccountRole,
OrganizationProfile,
} from '../../shared/services/account-management.service';
import { CredentialService } from '../../shared/services/credential.service';
import type {
AccountDialogComponent,
@@ -40,7 +36,14 @@ import {
SelectorOption,
} from '../../shared/ui/query-param-selector/query-param-selector.component';
import { MatCardModule } from '@angular/material/card';
import { AccountPage, AccountProfile } from '../../api';
import {
AccountPage,
AccountProfile,
AuthService,
InseAccountManagementModelOrganizationProfile,
UserRole,
} from '../../api';
import { StatusPipe } from '../../shared/pipes/status.pipe';
@Component({
selector: 'app-accounts',
@@ -53,6 +56,7 @@ import { AccountPage, AccountProfile } from '../../api';
MatInputModule,
MatSelectModule,
MatSnackBarModule,
MatTooltipModule,
MatDialogModule,
RolePipe,
DataTableComponent,
@@ -60,55 +64,48 @@ import { AccountPage, AccountProfile } from '../../api';
QueryParamInputComponent,
QueryParamSelectorComponent,
MatCardModule,
StatusPipe
],
templateUrl: './accounts.component.html',
styleUrl: './accounts.component.scss',
standalone: true,
})
export class AccountsComponent implements OnInit {
private readonly accountService = inject(AccountManagementService);
protected readonly credentialService = inject(CredentialService);
private readonly snackBar = inject(MatSnackBar);
private readonly router = inject(Router);
private readonly dialog = inject(MatDialog);
private readonly authService = inject(AuthService);
protected get availableRoles(): AccountRole[] {
if (this.credentialService.isEffectiveSuperAdmin()) {
return ['SUPER_ADMIN', 'ADMIN', 'MANAGER', 'USER'];
}
return ['MANAGER', 'USER'];
protected get isReadOnly(): boolean {
return this.credentialService.isEffectiveManager();
}
protected accounts: AccountProfile[] = [];
protected organizations: OrganizationProfile[] = [];
protected total = 0;
protected page = 0;
protected readonly pageSize = 10;
protected isLoading = false;
protected filterForm = new FormGroup({
search: new FormControl<string>(''),
organizationId: new FormControl<string>(''),
});
accountColumns: GenericColumn<AccountProfile>[] = [];
accountRoleTmp = viewChild.required<TemplateRef<any>>('accountRoleTmp');
accountStatusTmp = viewChild.required<TemplateRef<any>>('accountStatusTmp');
accountActionsTmp = viewChild.required<TemplateRef<any>>('accountActionsTmp');
selectorOptions: SelectorOption[] = [];
availableRoles = computed<UserRole[]>(() => {
if (this.credentialService.isEffectiveSuperAdmin()) {
return ['SUPER_ADMIN', 'ADMIN', 'MANAGER', 'USER'];
}
return ['MANAGER', 'USER'];
});
selectorOptions = computed<SelectorOption[]>(() => {
return this.organizations().map((org) => ({
value: org.id,
display_name: org.name,
}));
});
accountPage = input.required<AccountPage>();
constructor() {
effect(() => {
console.log('accountPage changed:', this.accountPage());
});
}
organizations =
input.required<InseAccountManagementModelOrganizationProfile[]>();
ngOnInit(): void {
this.loadOrganizations();
this.loadAccounts();
this.accountColumns = [
{
id: 'name',
@@ -150,52 +147,6 @@ export class AccountsComponent implements OnInit {
];
}
protected loadAccounts(page = this.page): void {
this.page = page;
this.isLoading = true;
this.accountService
.listAccounts({
page: this.page,
pageSize: this.pageSize,
search: this.filterForm.controls.search.value?.trim() || undefined,
organizationId:
this.filterForm.controls.organizationId.value || undefined,
})
.pipe(finalize(() => (this.isLoading = false)))
.subscribe({
next: (result) => {
this.accounts = result.items;
this.total = result.total;
},
error: () => {
this.snackBar.open('Accounts konnten nicht geladen werden.', 'OK', {
duration: 5000,
});
},
});
}
protected loadOrganizations(): void {
this.accountService.listOrganizations().subscribe({
next: (organizations) => {
this.organizations = organizations;
this.selectorOptions = organizations.map((org) => ({
value: org.id,
display_name: org.name,
}));
},
});
}
protected applyFilters(): void {
this.loadAccounts(0);
}
protected resetFilters(): void {
this.filterForm.reset({ search: '', organizationId: '' });
this.loadAccounts(0);
}
protected startCreate(): void {
this.openAccountDialog({ mode: 'create' });
}
@@ -207,15 +158,18 @@ export class AccountsComponent implements OnInit {
private saveDialogResult(result: AccountDialogResult): void {
const request =
result.mode === 'create'
? this.accountService.createAccount(result.payload)
: this.accountService.updateAccount(result.accountId, result.payload);
? this.authService.createAccount(result.payload)
: this.authService.updateAccount(result.accountId, result.payload);
request.subscribe({
next: () => {
this.snackBar.open('Account wurde gespeichert.', 'OK', {
duration: 3000,
});
this.loadAccounts(0);
this.router.navigate([], {
queryParams: { page: 0 },
queryParamsHandling: 'merge',
});
},
error: (error) => {
const message =
@@ -237,9 +191,9 @@ export class AccountsComponent implements OnInit {
{
mode: 'create' | 'edit';
account?: AccountProfile;
organizations: OrganizationProfile[];
organizations: InseAccountManagementModelOrganizationProfile[];
canSelectOrganization: boolean;
roles: AccountRole[];
roles: UserRole[];
},
AccountDialogResult | undefined
>(AccountDialogComponent, {
@@ -247,9 +201,9 @@ export class AccountsComponent implements OnInit {
maxWidth: 'calc(100vw - 32px)',
data: {
...data,
organizations: this.organizations,
organizations: this.organizations(),
canSelectOrganization: this.credentialService.isEffectiveSuperAdmin(),
roles: this.availableRoles,
roles: this.availableRoles(),
},
});
@@ -266,12 +220,15 @@ export class AccountsComponent implements OnInit {
return;
}
this.accountService.deleteAccount(account.id).subscribe({
this.authService.deleteAccount(account.id).subscribe({
next: () => {
this.snackBar.open('Account wurde deaktiviert.', 'OK', {
duration: 3000,
});
this.loadAccounts();
this.router.navigate([], {
queryParams: { page: 0 },
queryParamsHandling: 'merge',
});
},
error: () => {
this.snackBar.open('Account konnte nicht deaktiviert werden.', 'OK', {
@@ -281,6 +238,62 @@ export class AccountsComponent implements OnInit {
});
}
protected toggleAccountActivation(account: AccountProfile): void {
if (
!this.credentialService.isEffectiveSuperAdmin() ||
account.is_current ||
account.deleted
) {
return;
}
const activated = !account.activated;
const action = activated ? 'aktivieren' : 'deaktivieren';
import('../../shared/ui/confirmation-dialog/confirmation-dialog.component').then(
({ ConfirmationDialogComponent }) => {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
data: {
title: activated ? 'Account aktivieren' : 'Account deaktivieren',
message: `Möchtest Du den Account „${account.name}“ wirklich ${action}?`,
confirmText: activated ? 'Aktivieren' : 'Deaktivieren',
cancelText: 'Abbrechen',
},
});
dialogRef.componentInstance.confirmDelete.subscribe(() => {
this.updateAccountActivation(account, activated);
});
},
);
}
private updateAccountActivation(
account: AccountProfile,
activated: boolean,
): void {
this.authService.updateAccount(account.id, { activated }).subscribe({
next: () => {
this.snackBar.open(
activated ? 'Account wurde aktiviert.' : 'Account wurde deaktiviert.',
'OK',
{ duration: 3000 },
);
this.router.navigate([], {
queryParams: { page: 0 },
queryParamsHandling: 'merge',
});
},
error: () => {
this.snackBar.open(
'Account-Status konnte nicht geändert werden.',
'OK',
{ duration: 5000 },
);
},
});
}
protected async impersonate(account: AccountProfile): Promise<void> {
if (!this.canImpersonate(account)) {
return;
@@ -301,16 +314,8 @@ export class AccountsComponent implements OnInit {
}
}
protected get canPageBack(): boolean {
return this.page > 0;
}
protected get canPageForward(): boolean {
return (this.page + 1) * this.pageSize < this.total;
}
protected canImpersonate(account: AccountProfile): boolean {
if (account.is_current || account.deleted) {
if (account.is_current || account.deleted || !account.activated) {
return false;
}
@@ -232,7 +232,7 @@ export class AppLoginComponent implements OnDestroy {
}
if (error.status === 403) {
return 'Dieses Konto ist nicht für die Anmeldung freigeschaltet.';
return 'Dieser Account ist deaktiviert und kann sich nicht anmelden.';
}
return 'Die Anmeldung konnte nicht abgeschlossen werden. Bitte versuche es erneut.';
@@ -4,7 +4,6 @@ import {
OnDestroy,
signal,
DestroyRef,
OnInit,
effect,
} from '@angular/core';
import { CommonModule } from '@angular/common';