Additional audit logs

This commit is contained in:
Andre Beging
2022-05-31 17:57:41 +02:00
parent e21c9a7b52
commit c8af03e205
3 changed files with 12 additions and 8 deletions

View File

@@ -18,10 +18,6 @@ namespace FoodsharingSiegen.Contracts.Entity
/// </summary>
SaveProfile = 10,
/// <summary>
/// The set own password audit type
/// </summary>
SetOwnPassword = 20,
#region Usermanagement

View File

@@ -20,8 +20,6 @@ namespace FoodsharingSiegen.Server.Data
{
case AuditType.SaveProfile:
return "hat das eigene Profil gespeichert.";
case AuditType.SetOwnPassword:
return "hat das eigene Passwort geändert.";
case AuditType.CreateUser:
return $"hat den User {audit.Data1} erstellt.";
case AuditType.UpdateUser:

View File

@@ -11,6 +11,8 @@ namespace FoodsharingSiegen.Server.Data.Service
/// <seealso cref="ServiceBase"/>
public class UserService : ServiceBase
{
private AuditService AuditService { get; }
#region Setup/Teardown
/// <summary>
@@ -18,7 +20,8 @@ namespace FoodsharingSiegen.Server.Data.Service
/// </summary>
/// <param name="context">The context</param>
/// <param name="authService"></param>
public UserService(FsContext context, AuthService authService) : base(context, authService) { }
/// <param name="auditService"></param>
public UserService(FsContext context, AuthService authService, AuditService auditService) : base(context, authService) => AuditService = auditService;
#endregion
@@ -46,6 +49,8 @@ namespace FoodsharingSiegen.Server.Data.Service
var saveResult = await Context.SaveChangesAsync();
if (saveResult == 0) return new OperationResult<User>(new Exception("Fehler bei der Registrierung"));
await AuditService.Insert(AuditType.CreateUser, user.Mail);
return new OperationResult<User>(user);
}
catch (Exception e)
@@ -100,6 +105,10 @@ namespace FoodsharingSiegen.Server.Data.Service
var saveR = await Context.SaveChangesAsync();
if(saveR < 1) return new OperationResult(new Exception("Fehler beim Speichern"));
var auditData = CurrentUser?.Id == user.Id ? "sich selbst" : user.Mail;
await AuditService.Insert(AuditType.SetUserPassword, auditData);
return new OperationResult();
}
catch (Exception e)
@@ -146,6 +155,7 @@ namespace FoodsharingSiegen.Server.Data.Service
var saveR = await Context.SaveChangesAsync();
if(saveR < 1) return new OperationResult(new Exception("Fehler beim Speichern"));
await AuditService.Insert(AuditType.UpdateUser, user.Mail);
return new OperationResult();
}
catch (Exception e)