Compare commits
4 Commits
c0c18f2ddd
...
f4f04e4a42
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4f04e4a42 | ||
|
|
6807f2b6e6 | ||
|
|
0dd0c1bf4c | ||
|
|
87f26f9367 |
@@ -62,7 +62,32 @@ namespace FoodsharingSiegen.Contracts.Enums
|
||||
/// <summary>
|
||||
/// The remove interaction audit type
|
||||
/// </summary>
|
||||
RemoveInteraction = 100
|
||||
RemoveInteraction = 100,
|
||||
|
||||
/// <summary>
|
||||
/// The delete prospect images audit type
|
||||
/// </summary>
|
||||
DeleteProspectImages = 110,
|
||||
|
||||
/// <summary>
|
||||
/// The view prospect images audit type
|
||||
/// </summary>
|
||||
ViewProspectImages = 120,
|
||||
|
||||
/// <summary>
|
||||
/// The upload prospect image audit type
|
||||
/// </summary>
|
||||
UploadProspectImage = 130,
|
||||
|
||||
/// <summary>
|
||||
/// The request password reset audit type
|
||||
/// </summary>
|
||||
RequestPasswordReset = 140,
|
||||
|
||||
/// <summary>
|
||||
/// The change own password audit type
|
||||
/// </summary>
|
||||
ChangeOwnPassword = 150
|
||||
|
||||
#endregion Prospects
|
||||
}
|
||||
|
||||
@@ -251,6 +251,14 @@ namespace FoodsharingSiegen.Server.Auth
|
||||
user.ResetToken = resetToken;
|
||||
user.ResetTokenExpiry = DateTime.UtcNow.AddMinutes(30);
|
||||
|
||||
Context.Audits?.Add(new Audit
|
||||
{
|
||||
Created = DateTime.Now,
|
||||
Type = AuditType.RequestPasswordReset,
|
||||
UserID = user.Id,
|
||||
Data1 = user.Mail
|
||||
});
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
var resetLink = $"{baseUri.TrimEnd('/')}/reset-password/{resetToken}";
|
||||
|
||||
@@ -43,7 +43,20 @@ namespace FoodsharingSiegen.Server.Controls
|
||||
{
|
||||
var headerText = $"{type.Translate(AppSettings)} für {Prospect.Name} eintragen";
|
||||
|
||||
await InteractionDialog.ShowAsync(ModalService, new(type, Prospect.Id, headerText, OnDataChanged));
|
||||
Func<Task> onSuccess = async () =>
|
||||
{
|
||||
if (type == InteractionType.IdCheck && Prospect.Images != null && Prospect.Images.Count > 0)
|
||||
{
|
||||
await ConfirmDialog.ShowAsync(ModalService, "Personalausweisbilder löschen?", $"Möchtest du die Personalausweisbilder von {Prospect.Name} löschen? Diese werden für die weitere Bearbeitung nicht mehr benötigt und enthalten persönliche Daten.", async () =>
|
||||
{
|
||||
var result = await ProspectService.DeleteVerificationImagesAsync(Prospect.Id);
|
||||
await OnDataChanged();
|
||||
});
|
||||
}
|
||||
await OnDataChanged();
|
||||
};
|
||||
|
||||
await InteractionDialog.ShowAsync(ModalService, new(type, Prospect.Id, headerText, onSuccess));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,16 @@ namespace FoodsharingSiegen.Server.Data
|
||||
return $"hat dem Neuling {audit.Data1} folgendes hinzugefügt: {audit.Data2}";
|
||||
case AuditType.RemoveInteraction:
|
||||
return $"hat eine Interaktion bei {audit.Data1} gelöscht.";
|
||||
case AuditType.DeleteProspectImages:
|
||||
return $"hat die Bilder von {audit.Data1} gelöscht.";
|
||||
case AuditType.ViewProspectImages:
|
||||
return $"hat die Bilder von {audit.Data1} angesehen.";
|
||||
case AuditType.UploadProspectImage:
|
||||
return $"hat ein Bild für {audit.Data1} hochgeladen.";
|
||||
case AuditType.RequestPasswordReset:
|
||||
return $"hat ein Passwort-Reset für {audit.Data1} angefordert.";
|
||||
case AuditType.ChangeOwnPassword:
|
||||
return $"hat das eigene Passwort geändert.";
|
||||
case AuditType.None:
|
||||
default:
|
||||
return $"{audit.Data1}, {audit.Data2}";
|
||||
|
||||
@@ -61,29 +61,56 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Method Load
|
||||
#region Public Method GetCount
|
||||
|
||||
/// <summary>
|
||||
/// Loads the count (a. beging, 23.05.2022)
|
||||
/// Gets the total count (ab)
|
||||
/// </summary>
|
||||
/// <param name="count">The count</param>
|
||||
/// <param name="type">The type</param>
|
||||
/// <returns>A task containing an operation result of list audit</returns>
|
||||
public async Task<OperationResult<List<Audit>>> Load(int count, AuditType? type = null)
|
||||
/// <returns>A task containing an operation result of count</returns>
|
||||
public async Task<OperationResult<int>> GetCount(AuditType? type = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
|
||||
var query = Context.Audits?.Include(x => x.User).OrderByDescending(x => x.Created).AsQueryable();
|
||||
var query = Context.Audits?.AsQueryable();
|
||||
|
||||
if (count > 0)
|
||||
query = query?.Take(count);
|
||||
|
||||
if (type != null)
|
||||
query = query?.Where(x => x.Type == type);
|
||||
|
||||
var mat = query?.ToList();
|
||||
if (query == null) return new(0);
|
||||
|
||||
var count = await query.CountAsync();
|
||||
return new(count);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new(e);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Method LoadPage
|
||||
|
||||
/// <summary>
|
||||
/// Loads the page of audits (ab)
|
||||
/// </summary>
|
||||
/// <param name="skip">The skip count</param>
|
||||
/// <param name="take">The take count</param>
|
||||
/// <param name="type">The type</param>
|
||||
/// <returns>A task containing an operation result of list audit</returns>
|
||||
public async Task<OperationResult<List<Audit>>> LoadPage(int skip, int take, AuditType? type = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = Context.Audits?.Include(x => x.User).OrderByDescending(x => x.Created).AsQueryable();
|
||||
|
||||
if (type != null)
|
||||
query = query?.Where(x => x.Type == type);
|
||||
|
||||
query = query?.Skip(skip).Take(take);
|
||||
|
||||
var mat = await query!.ToListAsync();
|
||||
|
||||
if (mat != null) return new(mat);
|
||||
|
||||
|
||||
@@ -290,6 +290,8 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
await Context.ProspectImages!.AddAsync(image);
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
await AuditService.Insert(AuditType.UploadProspectImage, prospect.Name);
|
||||
|
||||
return new();
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -308,6 +310,16 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
.OrderBy(x => x.Created)
|
||||
.ToListAsync();
|
||||
|
||||
var prospectName = await Context.Prospects!
|
||||
.Where(x => x.Id == prospectId)
|
||||
.Select(x => x.Name)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(prospectName))
|
||||
{
|
||||
await AuditService.Insert(AuditType.ViewProspectImages, prospectName);
|
||||
}
|
||||
|
||||
return new(images);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -329,6 +341,7 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
if (prospect != null)
|
||||
{
|
||||
prospect.VerificationToken = null; // Clear token when images are deleted
|
||||
await AuditService.Insert(AuditType.DeleteProspectImages, prospect.Name);
|
||||
}
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
@@ -151,8 +151,14 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
|
||||
if (saveR < 1) return new(new Exception("Fehler beim Speichern"));
|
||||
|
||||
var auditData = CurrentUser?.Id == user.Id ? "sich selbst" : user.Mail;
|
||||
await AuditService.Insert(AuditType.SetUserPassword, auditData);
|
||||
if (CurrentUser?.Id == user.Id)
|
||||
{
|
||||
await AuditService.Insert(AuditType.ChangeOwnPassword);
|
||||
}
|
||||
else
|
||||
{
|
||||
await AuditService.Insert(AuditType.SetUserPassword, user.Mail);
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
@@ -127,9 +127,10 @@ namespace FoodsharingSiegen.Server.Dialogs
|
||||
Interaction.UserID = CurrentUser.Id;
|
||||
|
||||
var addR = await ProspectService.AddInteraction(Interaction);
|
||||
if (addR.Success && OnSuccess != null) await OnSuccess.Invoke();
|
||||
|
||||
await ModalService.Hide();
|
||||
|
||||
if (addR.Success && OnSuccess != null) await OnSuccess.Invoke();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
<DataGrid TItem="Audit"
|
||||
Data="@Audits"
|
||||
ReadData="@OnReadData"
|
||||
TotalItems="@TotalAudits"
|
||||
VirtualizeOptions="@(new() { DataGridHeight = "100%", DataGridMaxHeight = "100%"})"
|
||||
Virtualize="true"
|
||||
Responsive>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Blazorise.DataGrid;
|
||||
using FoodsharingSiegen.Contracts.Entity;
|
||||
using FoodsharingSiegen.Contracts.Helper;
|
||||
using FoodsharingSiegen.Server.Data.Service;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
@@ -26,16 +28,47 @@ namespace FoodsharingSiegen.Server.Pages
|
||||
/// </summary>
|
||||
private List<Audit>? Audits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the total audits (ab)
|
||||
/// </summary>
|
||||
private int TotalAudits { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Override InitializeDataAsync
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task InitializeDataAsync()
|
||||
protected override Task InitializeDataAsync()
|
||||
{
|
||||
var loadR = await AuditService?.Load(100)!;
|
||||
if (loadR.Success)
|
||||
Audits = loadR.Data;
|
||||
if (!CurrentUser.IsAdmin()) NavigationManager.NavigateTo("/");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method OnReadData
|
||||
|
||||
/// <summary>
|
||||
/// Called when data is read (ab)
|
||||
/// </summary>
|
||||
/// <param name="e">The params</param>
|
||||
private async Task OnReadData(DataGridReadDataEventArgs<Audit> e)
|
||||
{
|
||||
if (!CurrentUser.IsAdmin()) return;
|
||||
|
||||
var countLoad = await AuditService?.GetCount()!;
|
||||
if (countLoad.Success)
|
||||
TotalAudits = countLoad.Data;
|
||||
|
||||
// Default fallback if VirtualizeCount is not set, though Blazor shouldn't do this usually
|
||||
var limit = e.VirtualizeCount > 0 ? e.VirtualizeCount : 50;
|
||||
var offset = e.VirtualizeOffset;
|
||||
|
||||
var itemsLoad = await AuditService?.LoadPage(offset, limit)!;
|
||||
if (itemsLoad.Success)
|
||||
Audits = itemsLoad.Data;
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
{
|
||||
<div class="alert alert-success text-center">
|
||||
Wenn ein Benutzerkonto mit dieser E-Mail-Adresse existiert, wurde eine E-Mail mit weiteren Anweisungen versendet.
|
||||
<br><br>
|
||||
<small><b>Hinweis:</b> Bitte überprüfe auch deinen Spam-Ordner, falls du künftige E-Mails nicht im regulären Posteingang findest.</small>
|
||||
</div>
|
||||
<div class="text-center mt-4">
|
||||
<a href="/login" class="btn btn-outline-primary"><i class="fas fa-arrow-left mr-2"></i> Zurück zum Login</a>
|
||||
|
||||
@@ -126,6 +126,10 @@ namespace FoodsharingSiegen.Server.Pages
|
||||
await ConfirmDialog.ShowAsync(ModalService, "Bestätigen", $"Soll eine E-Mail zum Festlegen des Passworts an {user.Mail} gesendet werden?", async () =>
|
||||
{
|
||||
await AuthService.InitiateInitialPasswordSetup(user.Mail, NavigationManager.BaseUri);
|
||||
if (Notification != null)
|
||||
{
|
||||
await Notification.Success("E-Mail gesendet. Bitte weise den Benutzer darauf hin, auch den Spam-Ordner zu prüfen.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -64,15 +64,15 @@
|
||||
</NavLink>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="nav-item px-3">
|
||||
<div @onclick="NavLinkClickedAsync">
|
||||
<NavLink class="nav-link" href="audit" Match="NavLinkMatch.All">
|
||||
<span class="fa-solid fa-clock-rotate-left mr-2" aria-hidden="true" style="font-size: 1.4em;"></span> Aktivitäten
|
||||
</NavLink>
|
||||
<div class="nav-item px-3">
|
||||
<div @onclick="NavLinkClickedAsync">
|
||||
<NavLink class="nav-link" href="audit" Match="NavLinkMatch.All">
|
||||
<span class="fa-solid fa-clock-rotate-left mr-2" aria-hidden="true" style="font-size: 1.4em;"></span> Aktivitäten
|
||||
</NavLink>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="flex-grow-1"></div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user