Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Turnierplan.App/Client/src/app/i18n/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const de = {
},
DeleteUser: {
Title: 'Benutzer löschen',
Info: 'Wenn Sie eine Benutzer löschen, werden automatisch alle darin enthaltenen Organisationen, Turniere, Spielstätten sämtliche hochgeladenen Bilder mitgelöscht. Diese Aktion kann nicht widerrufen werden!',
Info: 'Wenn Sie eine Benutzer löschen, werden die Organisationen des Benutzers nicht mitgelöscht und bleiben weiterhin für alle Administratoren sichtbar.',
IdConfirmation: 'Benutzer-ID:',
SuccessToast: {
Title: 'Benutzer wurde gelöscht',
Expand Down Expand Up @@ -941,6 +941,7 @@ export const de = {
ApiKey: 'API-Schlüssel',
User: 'Benutzer'
},
PrincipalNotFound: 'Der Prinzipal konnte nicht mehr gefunden werden. Wurde der Nutzer/API-Schlüssel gelöscht?',
TotalCount: 'Gesamt:',
Id: 'ID:',
CreatedAt: 'Erstellt am:',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@let displayName = displayName$ | async;
@let notFound = displayName?.found === false;

@switch (principal.kind) {
@case (PrincipalKind.ApiKey) {
<i class="bi bi-key" [ngbTooltip]="'Portal.RbacManagement.PrincipalKind.ApiKey' | translate"></i>
Expand All @@ -6,4 +9,9 @@
<i class="bi bi-person" [ngbTooltip]="'Portal.RbacManagement.PrincipalKind.User' | translate"></i>
}
}
<span class="ms-2">{{ displayName$ | async }}</span>

@if (notFound) {
<i class="ms-2 text-danger bi bi-exclamation-diamond-fill" [ngbTooltip]="'Portal.RbacManagement.PrincipalNotFound' | translate"></i>
}

<span class="ms-2" [ngClass]="{ 'text-danger': notFound }">{{ displayName?.value }}</span>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { map } from 'rxjs/operators';
export class RbacPrincipalComponent implements OnInit {
protected readonly PrincipalKind = PrincipalKind;

protected displayName$?: Observable<string>;
protected displayName$?: Observable<{ found: boolean; value: string | undefined }>;

@Input()
public principal!: PrincipalDto;
Expand All @@ -26,8 +26,8 @@ export class RbacPrincipalComponent implements OnInit {
principalId: this.principal.principalId
})
.pipe(
map((result) => result.name),
catchError(() => of(this.principal.principalId))
map((result) => ({ found: true, value: result.name })),
catchError(() => of({ found: false, value: this.principal.principalId }))
);
}
}
7 changes: 2 additions & 5 deletions src/Turnierplan.App/Endpoints/Users/DeleteUserEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ private static async Task<IResult> Handle(
return Results.NotFound();
}

var result = await deletionHelper.DeleteUserAsync(user, cancellationToken).ConfigureAwait(false);
repository.Remove(user);

if (!result)
{
return Results.InternalServerError("The deletion of the user failed. Please check the application logs for details.");
}
await repository.UnitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

return Results.NoContent();
}
Expand Down
32 changes: 0 additions & 32 deletions src/Turnierplan.App/Helpers/DeletionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
using Turnierplan.Core.Image;
using Turnierplan.Core.Organization;
using Turnierplan.Core.Tournament;
using Turnierplan.Core.User;
using Turnierplan.Core.Venue;
using Turnierplan.ImageStorage;

namespace Turnierplan.App.Helpers;

internal interface IDeletionHelper
{
Task<bool> DeleteUserAsync(User user, CancellationToken cancellationToken);

Task<bool> DeleteOrganizationAsync(Organization organization, CancellationToken cancellationToken);
}

internal sealed class DeletionHelper : IDeletionHelper
{
private readonly IUserRepository _userRepository;
private readonly IOrganizationRepository _organizationRepository;
private readonly ITournamentRepository _tournamentRepository;
private readonly IVenueRepository _venueRepository;
Expand All @@ -25,15 +21,13 @@ internal sealed class DeletionHelper : IDeletionHelper
private readonly ILogger<DeletionHelper> _logger;

public DeletionHelper(
IUserRepository userRepository,
IOrganizationRepository organizationRepository,
ITournamentRepository tournamentRepository,
IVenueRepository venueRepository,
IImageRepository imageRepository,
IImageStorage imageStorage,
ILogger<DeletionHelper> logger)
{
_userRepository = userRepository;
_organizationRepository = organizationRepository;
_tournamentRepository = tournamentRepository;
_venueRepository = venueRepository;
Expand All @@ -42,32 +36,6 @@ public DeletionHelper(
_logger = logger;
}

public async Task<bool> DeleteUserAsync(User user, CancellationToken cancellationToken)
{
// TODO: Decide how to handle this (there is no longer a 1-n relation between user and organisation)
// When this is decided: Update the information text on the "delete user" screen in the frontend

// foreach (var organization in user.Organizations.ToList()) // ToList() to avoid invalid operation exception
// {
// cancellationToken.ThrowIfCancellationRequested();
//
// var result = await DeleteOrganizationAsync(organization, cancellationToken).ConfigureAwait(false);
//
// if (!result)
// {
// return false;
// }
// }

cancellationToken.ThrowIfCancellationRequested();

_userRepository.Remove(user);

await _userRepository.UnitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

return true;
}

public async Task<bool> DeleteOrganizationAsync(Organization organization, CancellationToken cancellationToken)
{
var hasNonDeletedImages = false;
Expand Down
Loading