Skip to content

Commit

Permalink
Prevent overload audits when deleting training
Browse files Browse the repository at this point in the history
  • Loading branch information
TDroogers committed Sep 19, 2024
1 parent 77a7c42 commit 1a63a3b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 14 deletions.
36 changes: 27 additions & 9 deletions src/Client/Pages/Configuration/DefaultSchedule.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,33 @@
@if (_defaults is not null)
{
if (_defaults.DefaultSchedules?.Any() == true)
{
<MudDataGrid Items="@_defaults.DefaultSchedules" ReadOnly="true" Filterable="false" SortMode="@SortMode.None">
<Columns>
<PropertyColumn Property="x => x.Name" Title="@L["Description"]"/>
<PropertyColumn Property="x => x.ValidFromDefault" Title="@L["ValidFromDefault"]"/>
<PropertyColumn Property="x => x.ValidUntilDefault" Title="@L["ValidUntilDefault"]"/>
<PropertyColumn Property="x => x.Order" Title="@L["Order"]"/>
</Columns>
</MudDataGrid>
{<MudDataGrid Items="@_defaults.DefaultSchedules" Striped="true" Hover="true">
<Columns>
<HierarchyColumn T="DefaultSchedule"/>
<PropertyColumn Property="x => x.Name" Title="@L["Name"]" CellClassFunc="@(x => $"trainingType-{x.RoosterTrainingTypeId}")"/>
<PropertyColumn Property="x => x.WeekDay" Title="@L["Weekday"]">
<CellTemplate>
@LApp[context.Item.WeekDay.ToString() ?? "None"]
</CellTemplate>
</PropertyColumn>
<TemplateColumn Title="@L["TimeStart"]">
<CellTemplate>
@if (context.Item.ShowTime)
{
<p>@context.Item.TimeStart</p>
}
</CellTemplate>
</TemplateColumn>
<TemplateColumn Title="@L["TimeEnd"]">
<CellTemplate>
@if (context.Item.ShowTime)
{
<p>@context.Item.TimeEnd</p>
}
</CellTemplate>
</TemplateColumn>
</Columns>
</MudDataGrid>
}
}
else
Expand Down
3 changes: 2 additions & 1 deletion src/Client/Pages/Configuration/DefaultSchedule.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

namespace Drogecode.Knrm.Oefenrooster.Client.Pages.Configuration;

public partial class DefaultSchedule : IDisposable
public sealed partial class DefaultSchedule : IDisposable
{
[Inject] private IStringLocalizer<DefaultSchedule> L { get; set; } = default!;
[Inject] private IStringLocalizer<App> LApp { get; set; } = default!;
[Inject] private DefaultScheduleRepository _defaultScheduleRepository { get; set; } = default!;
private CancellationTokenSource _cls = new();
private GetAllDefaultScheduleResponse? _defaults;
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Pages/Dashboard/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public sealed partial class Index : IDisposable
private string? _name;
private Guid _userId;
private bool _loading = true;
private const int TAKE = 30;
private const int TAKE = 15;
private int _total = TAKE;
private int _skip = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/Client/Pages/Planner/UserDetails.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public sealed partial class UserDetails : IDisposable
private List<PlannerTrainingType>? _trainingTypes;
private IEnumerable<DrogeUser> _selectedUsersAction;
private bool _updatingSelection = false;
private const int TAKE = 30;
private const int TAKE = 15;
private int _total = TAKE;
private int _skip = 0;

Expand Down
3 changes: 3 additions & 0 deletions src/Server/Controllers/ScheduleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ public async Task<ActionResult<bool>> DeleteTraining(Guid id, CancellationToken
return Unauthorized();
foreach (var user in training.Training.PlanUsers)
{
if (!user.Assigned)
continue;
user.Assigned = false;
var body = new PatchAssignedUserRequest
{
Expand All @@ -482,6 +484,7 @@ public async Task<ActionResult<bool>> DeleteTraining(Guid id, CancellationToken
}

var result = await _scheduleService.DeleteTraining(userId, customerId, id, clt);
await _auditService.Log(userId, AuditType.DeleteTraining, customerId, null, id);
return result;
}
catch (Exception ex)
Expand Down
1 change: 1 addition & 0 deletions src/Shared/Enums/AuditType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public enum AuditType
CatchAll = 7,
PreComRaw = 8,
UpdateLinkUserUserForUser = 9,
DeleteTraining = 10,
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="FluentAssertions" Version="6.12.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="Xunit.DependencyInjection" Version="9.3.1" />
<PackageReference Include="Xunit.DependencyInjection" Version="9.4.0" />
<PackageReference Include="Xunit.DependencyInjection.Logging" Version="9.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="Xunit.DependencyInjection" Version="9.3.1" />
<PackageReference Include="Xunit.DependencyInjection" Version="9.4.0" />
<PackageReference Include="Xunit.DependencyInjection.Logging" Version="9.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit 1a63a3b

Please sign in to comment.