Skip to content

Commit 3a5c6b2

Browse files
authored
Revert "Fix activity audit trail not recording board mutations (#581)"
This reverts commit 5e064d4.
1 parent 5e064d4 commit 3a5c6b2

10 files changed

Lines changed: 19 additions & 514 deletions

File tree

backend/src/Taskdeck.Api/Extensions/ApplicationServiceRegistration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection
3030
services.AddScoped<ICaptureService, CaptureService>();
3131
services.AddScoped<ICaptureTriageService, CaptureTriageService>();
3232
services.AddScoped<HistoryService>();
33-
services.AddScoped<IHistoryService>(sp => sp.GetRequiredService<HistoryService>());
3433
services.AddScoped<IAutomationProposalService, AutomationProposalService>();
3534
services.AddScoped<IAutomationPolicyEngine, AutomationPolicyEngine>();
3635
services.AddScoped<IAutomationPlannerService, AutomationPlannerService>();

backend/src/Taskdeck.Application/Services/BoardService.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Taskdeck.Application.Interfaces;
33
using Taskdeck.Domain.Common;
44
using Taskdeck.Domain.Entities;
5-
using Taskdeck.Domain.Enums;
65
using Taskdeck.Domain.Exceptions;
76

87
namespace Taskdeck.Application.Services;
@@ -12,30 +11,20 @@ public class BoardService
1211
private readonly IUnitOfWork _unitOfWork;
1312
private readonly IAuthorizationService? _authorizationService;
1413
private readonly IBoardRealtimeNotifier _realtimeNotifier;
15-
private readonly IHistoryService? _historyService;
1614

1715
public BoardService(IUnitOfWork unitOfWork)
18-
: this(unitOfWork, authorizationService: null, realtimeNotifier: null, historyService: null)
16+
: this(unitOfWork, authorizationService: null, realtimeNotifier: null)
1917
{
2018
}
2119

2220
public BoardService(
2321
IUnitOfWork unitOfWork,
2422
IAuthorizationService? authorizationService,
25-
IBoardRealtimeNotifier? realtimeNotifier = null,
26-
IHistoryService? historyService = null)
23+
IBoardRealtimeNotifier? realtimeNotifier = null)
2724
{
2825
_unitOfWork = unitOfWork;
2926
_authorizationService = authorizationService;
3027
_realtimeNotifier = realtimeNotifier ?? NoOpBoardRealtimeNotifier.Instance;
31-
_historyService = historyService;
32-
}
33-
34-
private async Task SafeLogAsync(string entityType, Guid entityId, AuditAction action, Guid? userId = null, string? changes = null)
35-
{
36-
if (_historyService == null) return;
37-
try { await _historyService.LogActionAsync(entityType, entityId, action, userId, changes); }
38-
catch (Exception) { /* Audit is secondary — never crash the mutation */ }
3928
}
4029

4130
public async Task<Result<BoardDto>> CreateBoardAsync(CreateBoardDto dto, Guid actingUserId, CancellationToken cancellationToken = default)
@@ -150,7 +139,6 @@ private async Task<Result<BoardDto>> CreateBoardInternalAsync(CreateBoardDto dto
150139
await _realtimeNotifier.NotifyBoardMutationAsync(
151140
new BoardRealtimeEvent(board.Id, "board", "created", board.Id, DateTimeOffset.UtcNow),
152141
cancellationToken);
153-
await SafeLogAsync("board", board.Id, AuditAction.Created, ownerId, $"name={board.Name}");
154142

155143
return Result.Success(MapToDto(board));
156144
}
@@ -183,12 +171,6 @@ private async Task<Result<BoardDto>> UpdateBoardInternalAsync(Guid id, UpdateBoa
183171
await _realtimeNotifier.NotifyBoardMutationAsync(
184172
new BoardRealtimeEvent(board.Id, "board", "updated", board.Id, DateTimeOffset.UtcNow),
185173
cancellationToken);
186-
if (dto.IsArchived == true)
187-
await SafeLogAsync("board", board.Id, AuditAction.Archived, changes: $"name={board.Name}");
188-
else if (dto.IsArchived == false)
189-
await SafeLogAsync("board", board.Id, AuditAction.Updated, changes: $"unarchived; name={board.Name}");
190-
else
191-
await SafeLogAsync("board", board.Id, AuditAction.Updated, changes: $"name={board.Name}");
192174
return Result.Success(MapToDto(board));
193175
}
194176
catch (DomainException ex)
@@ -217,7 +199,6 @@ private async Task<Result> DeleteBoardInternalAsync(Guid id, CancellationToken c
217199
await _realtimeNotifier.NotifyBoardMutationAsync(
218200
new BoardRealtimeEvent(board.Id, "board", "archived", board.Id, DateTimeOffset.UtcNow),
219201
cancellationToken);
220-
await SafeLogAsync("board", board.Id, AuditAction.Archived, changes: $"name={board.Name}");
221202
return Result.Success();
222203
}
223204

backend/src/Taskdeck.Application/Services/CardService.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,16 @@ public class CardService
1111
{
1212
private readonly IUnitOfWork _unitOfWork;
1313
private readonly IBoardRealtimeNotifier _realtimeNotifier;
14-
private readonly IHistoryService? _historyService;
1514

1615
public CardService(IUnitOfWork unitOfWork)
17-
: this(unitOfWork, realtimeNotifier: null, historyService: null)
16+
: this(unitOfWork, realtimeNotifier: null)
1817
{
1918
}
2019

21-
public CardService(IUnitOfWork unitOfWork, IBoardRealtimeNotifier? realtimeNotifier = null, IHistoryService? historyService = null)
20+
public CardService(IUnitOfWork unitOfWork, IBoardRealtimeNotifier? realtimeNotifier = null)
2221
{
2322
_unitOfWork = unitOfWork;
2423
_realtimeNotifier = realtimeNotifier ?? NoOpBoardRealtimeNotifier.Instance;
25-
_historyService = historyService;
26-
}
27-
28-
private async Task SafeLogAsync(string entityType, Guid entityId, AuditAction action, Guid? userId = null, string? changes = null)
29-
{
30-
if (_historyService == null) return;
31-
try { await _historyService.LogActionAsync(entityType, entityId, action, userId, changes); }
32-
catch (Exception) { /* Audit is secondary — never crash the mutation */ }
3324
}
3425

3526
public async Task<Result<CardDto>> CreateCardAsync(CreateCardDto dto, CancellationToken cancellationToken = default)
@@ -83,7 +74,6 @@ public async Task<Result<CardDto>> CreateCardAsync(
8374
await _realtimeNotifier.NotifyBoardMutationAsync(
8475
new BoardRealtimeEvent(card.BoardId, "card", "created", card.Id, DateTimeOffset.UtcNow),
8576
cancellationToken);
86-
await SafeLogAsync("card", card.Id, AuditAction.Created, changes: $"title={card.Title}");
8777

8878
var createdCard = await _unitOfWork.Cards.GetByIdWithLabelsAsync(card.Id, cancellationToken);
8979
return Result.Success(MapToDto(createdCard!));
@@ -144,7 +134,6 @@ public async Task<Result<CardDto>> UpdateCardAsync(
144134
await _realtimeNotifier.NotifyBoardMutationAsync(
145135
new BoardRealtimeEvent(card.BoardId, "card", "updated", card.Id, DateTimeOffset.UtcNow),
146136
cancellationToken);
147-
await SafeLogAsync("card", card.Id, AuditAction.Updated, actorUserId);
148137

149138
var updatedCard = await _unitOfWork.Cards.GetByIdWithLabelsAsync(id, cancellationToken);
150139
return Result.Success(MapToDto(updatedCard!));
@@ -224,7 +213,6 @@ public async Task<Result<CardDto>> MoveCardAsync(Guid id, MoveCardDto dto, Cance
224213
await _realtimeNotifier.NotifyBoardMutationAsync(
225214
new BoardRealtimeEvent(card.BoardId, "card", "moved", card.Id, DateTimeOffset.UtcNow),
226215
cancellationToken);
227-
await SafeLogAsync("card", card.Id, AuditAction.Moved, changes: $"target_column={dto.TargetColumnId}; position={dto.TargetPosition}");
228216

229217
var movedCard = await _unitOfWork.Cards.GetByIdWithLabelsAsync(id, cancellationToken);
230218
return Result.Success(MapToDto(movedCard!));
@@ -311,7 +299,6 @@ public async Task<Result> DeleteCardAsync(Guid id, CancellationToken cancellatio
311299
await _realtimeNotifier.NotifyBoardMutationAsync(
312300
new BoardRealtimeEvent(card.BoardId, "card", "deleted", card.Id, DateTimeOffset.UtcNow),
313301
cancellationToken);
314-
await SafeLogAsync("card", card.Id, AuditAction.Deleted, changes: $"title={card.Title}");
315302

316303
return Result.Success();
317304
}

backend/src/Taskdeck.Application/Services/ColumnService.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Taskdeck.Application.Interfaces;
33
using Taskdeck.Domain.Common;
44
using Taskdeck.Domain.Entities;
5-
using Taskdeck.Domain.Enums;
65
using Taskdeck.Domain.Exceptions;
76

87
namespace Taskdeck.Application.Services;
@@ -11,25 +10,16 @@ public class ColumnService
1110
{
1211
private readonly IUnitOfWork _unitOfWork;
1312
private readonly IBoardRealtimeNotifier _realtimeNotifier;
14-
private readonly IHistoryService? _historyService;
1513

1614
public ColumnService(IUnitOfWork unitOfWork)
17-
: this(unitOfWork, realtimeNotifier: null, historyService: null)
15+
: this(unitOfWork, realtimeNotifier: null)
1816
{
1917
}
2018

21-
public ColumnService(IUnitOfWork unitOfWork, IBoardRealtimeNotifier? realtimeNotifier = null, IHistoryService? historyService = null)
19+
public ColumnService(IUnitOfWork unitOfWork, IBoardRealtimeNotifier? realtimeNotifier = null)
2220
{
2321
_unitOfWork = unitOfWork;
2422
_realtimeNotifier = realtimeNotifier ?? NoOpBoardRealtimeNotifier.Instance;
25-
_historyService = historyService;
26-
}
27-
28-
private async Task SafeLogAsync(string entityType, Guid entityId, AuditAction action, Guid? userId = null, string? changes = null)
29-
{
30-
if (_historyService == null) return;
31-
try { await _historyService.LogActionAsync(entityType, entityId, action, userId, changes); }
32-
catch (Exception) { /* Audit is secondary — never crash the mutation */ }
3323
}
3424

3525
public async Task<Result<ColumnDto>> CreateColumnAsync(CreateColumnDto dto, CancellationToken cancellationToken = default)
@@ -55,7 +45,6 @@ public async Task<Result<ColumnDto>> CreateColumnAsync(CreateColumnDto dto, Canc
5545
await _realtimeNotifier.NotifyBoardMutationAsync(
5646
new BoardRealtimeEvent(column.BoardId, "column", "created", column.Id, DateTimeOffset.UtcNow),
5747
cancellationToken);
58-
await SafeLogAsync("column", column.Id, AuditAction.Created, changes: $"name={column.Name}");
5948

6049
return Result.Success(MapToDto(column));
6150
}
@@ -78,7 +67,6 @@ public async Task<Result<ColumnDto>> UpdateColumnAsync(Guid id, UpdateColumnDto
7867
await _realtimeNotifier.NotifyBoardMutationAsync(
7968
new BoardRealtimeEvent(column.BoardId, "column", "updated", column.Id, DateTimeOffset.UtcNow),
8069
cancellationToken);
81-
await SafeLogAsync("column", column.Id, AuditAction.Updated);
8270

8371
return Result.Success(MapToDto(column));
8472
}
@@ -117,7 +105,6 @@ public async Task<Result> DeleteColumnAsync(Guid id, CancellationToken cancellat
117105
await _realtimeNotifier.NotifyBoardMutationAsync(
118106
new BoardRealtimeEvent(column.BoardId, "column", "deleted", column.Id, DateTimeOffset.UtcNow),
119107
cancellationToken);
120-
await SafeLogAsync("column", column.Id, AuditAction.Deleted, changes: $"name={column.Name}");
121108

122109
return Result.Success();
123110
}
@@ -179,7 +166,6 @@ public async Task<Result<IEnumerable<ColumnDto>>> ReorderColumnsAsync(Guid board
179166
await _realtimeNotifier.NotifyBoardMutationAsync(
180167
new BoardRealtimeEvent(boardId, "column", "reordered", null, DateTimeOffset.UtcNow),
181168
cancellationToken);
182-
await SafeLogAsync("column", boardId, AuditAction.Updated, changes: $"reordered; count={dto.ColumnIds.Count}");
183169

184170
// Return reordered columns
185171
var reorderedColumns = dto.ColumnIds.Select(id => MapToDto(columnDict[id]));

backend/src/Taskdeck.Application/Services/HistoryService.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ public async Task<Result> LogActionAsync(string entityType, Guid entityId, Audit
7070
{
7171
return Result.Failure(ex.ErrorCode, ex.Message);
7272
}
73-
catch (Exception)
74-
{
75-
// Audit logging is secondary to the mutation — never let infrastructure
76-
// failures (e.g. DB full, concurrency) crash the calling operation.
77-
return Result.Failure(ErrorCodes.UnexpectedError, $"Failed to persist audit log for {entityType}/{entityId}/{action}");
78-
}
7973
}
8074

8175
private static AuditLogDto MapToDto(AuditLog log)

backend/src/Taskdeck.Application/Services/IHistoryService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Taskdeck.Application.Services;
66

77
/// <summary>
88
/// Service interface for audit log and history operations.
9+
/// SCAFFOLDING: Implementation pending.
910
/// </summary>
1011
public interface IHistoryService
1112
{

backend/src/Taskdeck.Application/Services/LabelService.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Taskdeck.Application.Interfaces;
33
using Taskdeck.Domain.Common;
44
using Taskdeck.Domain.Entities;
5-
using Taskdeck.Domain.Enums;
65
using Taskdeck.Domain.Exceptions;
76

87
namespace Taskdeck.Application.Services;
@@ -11,25 +10,16 @@ public class LabelService
1110
{
1211
private readonly IUnitOfWork _unitOfWork;
1312
private readonly IBoardRealtimeNotifier _realtimeNotifier;
14-
private readonly IHistoryService? _historyService;
1513

1614
public LabelService(IUnitOfWork unitOfWork)
17-
: this(unitOfWork, realtimeNotifier: null, historyService: null)
15+
: this(unitOfWork, realtimeNotifier: null)
1816
{
1917
}
2018

21-
public LabelService(IUnitOfWork unitOfWork, IBoardRealtimeNotifier? realtimeNotifier = null, IHistoryService? historyService = null)
19+
public LabelService(IUnitOfWork unitOfWork, IBoardRealtimeNotifier? realtimeNotifier = null)
2220
{
2321
_unitOfWork = unitOfWork;
2422
_realtimeNotifier = realtimeNotifier ?? NoOpBoardRealtimeNotifier.Instance;
25-
_historyService = historyService;
26-
}
27-
28-
private async Task SafeLogAsync(string entityType, Guid entityId, AuditAction action, Guid? userId = null, string? changes = null)
29-
{
30-
if (_historyService == null) return;
31-
try { await _historyService.LogActionAsync(entityType, entityId, action, userId, changes); }
32-
catch (Exception) { /* Audit is secondary — never crash the mutation */ }
3323
}
3424

3525
public async Task<Result<LabelDto>> CreateLabelAsync(CreateLabelDto dto, CancellationToken cancellationToken = default)
@@ -46,7 +36,6 @@ public async Task<Result<LabelDto>> CreateLabelAsync(CreateLabelDto dto, Cancell
4636
await _realtimeNotifier.NotifyBoardMutationAsync(
4737
new BoardRealtimeEvent(label.BoardId, "label", "created", label.Id, DateTimeOffset.UtcNow),
4838
cancellationToken);
49-
await SafeLogAsync("label", label.Id, AuditAction.Created, changes: $"name={label.Name}");
5039

5140
return Result.Success(MapToDto(label));
5241
}
@@ -69,7 +58,6 @@ public async Task<Result<LabelDto>> UpdateLabelAsync(Guid id, UpdateLabelDto dto
6958
await _realtimeNotifier.NotifyBoardMutationAsync(
7059
new BoardRealtimeEvent(label.BoardId, "label", "updated", label.Id, DateTimeOffset.UtcNow),
7160
cancellationToken);
72-
await SafeLogAsync("label", label.Id, AuditAction.Updated);
7361

7462
return Result.Success(MapToDto(label));
7563
}
@@ -105,7 +93,6 @@ public async Task<Result> DeleteLabelAsync(Guid id, CancellationToken cancellati
10593
await _realtimeNotifier.NotifyBoardMutationAsync(
10694
new BoardRealtimeEvent(label.BoardId, "label", "deleted", label.Id, DateTimeOffset.UtcNow),
10795
cancellationToken);
108-
await SafeLogAsync("label", label.Id, AuditAction.Deleted, changes: $"name={label.Name}");
10996

11097
return Result.Success();
11198
}

0 commit comments

Comments
 (0)