From 06f9f156f6eab03c0debcc537803d8771ac1bfa6 Mon Sep 17 00:00:00 2001 From: Nick Krantz Date: Sun, 1 Jun 2025 20:19:57 -0500 Subject: [PATCH] omit userId from `MarkTaskAsCompletedCommand` query. The userId from the notification will be used --- .../Repositories/INotificationRepository.cs | 3 +-- .../IMarkNotificationsForTaskAsDeletedCommand.cs | 3 +-- .../Commands/MarkNotificationsForTaskAsDeletedCommand.cs | 4 ++-- src/Core/Vault/Commands/MarkTaskAsCompletedCommand.cs | 2 +- .../Repositories/NotificationRepository.cs | 3 +-- .../Repositories/NotificationRepository.cs | 8 ++++---- .../Notification_MarkAsDeletedByTask.sql | 8 +++----- .../2025-05-30_00_Notification_MarkAsDeletedByTask.sql | 8 +++----- 8 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/Core/NotificationCenter/Repositories/INotificationRepository.cs b/src/Core/NotificationCenter/Repositories/INotificationRepository.cs index d52049e65b..565cbafa5f 100644 --- a/src/Core/NotificationCenter/Repositories/INotificationRepository.cs +++ b/src/Core/NotificationCenter/Repositories/INotificationRepository.cs @@ -37,9 +37,8 @@ public interface INotificationRepository : IRepository /// Marks notifications as deleted by a task Id. /// /// The unique identifier of the task. - /// User Id /// /// A collection of users ids for the notifications that are now marked as deleted. /// - Task> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId); + Task> MarkNotificationsAsDeletedByTask(Guid taskId); } diff --git a/src/Core/Vault/Commands/Interfaces/IMarkNotificationsForTaskAsDeletedCommand.cs b/src/Core/Vault/Commands/Interfaces/IMarkNotificationsForTaskAsDeletedCommand.cs index 97febb7202..90566b4d83 100644 --- a/src/Core/Vault/Commands/Interfaces/IMarkNotificationsForTaskAsDeletedCommand.cs +++ b/src/Core/Vault/Commands/Interfaces/IMarkNotificationsForTaskAsDeletedCommand.cs @@ -6,7 +6,6 @@ public interface IMarkNotificationsForTaskAsDeletedCommand /// Marks notifications associated with a given taskId as deleted. /// /// The unique identifier of the task to complete - /// User Id /// A task representing the async operation - Task MarkAsDeletedAsync(Guid taskId, Guid userId); + Task MarkAsDeletedAsync(Guid taskId); } diff --git a/src/Core/Vault/Commands/MarkNotificationsForTaskAsDeletedCommand.cs b/src/Core/Vault/Commands/MarkNotificationsForTaskAsDeletedCommand.cs index 2165bc3fe5..8d1e6e4538 100644 --- a/src/Core/Vault/Commands/MarkNotificationsForTaskAsDeletedCommand.cs +++ b/src/Core/Vault/Commands/MarkNotificationsForTaskAsDeletedCommand.cs @@ -18,9 +18,9 @@ public class MarkNotificationsForTaskAsDeletedCommand : IMarkNotificationsForTas } - public async Task MarkAsDeletedAsync(Guid taskId, Guid userId) + public async Task MarkAsDeletedAsync(Guid taskId) { - var userIds = await _notificationRepository.MarkNotificationsAsDeletedByTask(taskId, userId); + var userIds = await _notificationRepository.MarkNotificationsAsDeletedByTask(taskId); // For each user associated with the notifications, send a push notification so local tasks can be updated. var uniqueUserIds = userIds.Distinct(); diff --git a/src/Core/Vault/Commands/MarkTaskAsCompletedCommand.cs b/src/Core/Vault/Commands/MarkTaskAsCompletedCommand.cs index 93fe162ce9..8a12910bb8 100644 --- a/src/Core/Vault/Commands/MarkTaskAsCompletedCommand.cs +++ b/src/Core/Vault/Commands/MarkTaskAsCompletedCommand.cs @@ -52,6 +52,6 @@ public class MarkTaskAsCompletedCommand : IMarkTaskAsCompleteCommand await _securityTaskRepository.ReplaceAsync(task); // Mark all notifications related to this task as deleted - await _markNotificationsForTaskAsDeletedAsync.MarkAsDeletedAsync(taskId, _currentContext.UserId.Value); + await _markNotificationsForTaskAsDeletedAsync.MarkAsDeletedAsync(taskId); } } diff --git a/src/Infrastructure.Dapper/NotificationCenter/Repositories/NotificationRepository.cs b/src/Infrastructure.Dapper/NotificationCenter/Repositories/NotificationRepository.cs index 8739198586..63b1c21f49 100644 --- a/src/Infrastructure.Dapper/NotificationCenter/Repositories/NotificationRepository.cs +++ b/src/Infrastructure.Dapper/NotificationCenter/Repositories/NotificationRepository.cs @@ -57,7 +57,7 @@ public class NotificationRepository : Repository, INotificat }; } - public async Task> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId) + public async Task> MarkNotificationsAsDeletedByTask(Guid taskId) { await using var connection = new SqlConnection(ConnectionString); @@ -66,7 +66,6 @@ public class NotificationRepository : Repository, INotificat new { TaskId = taskId, - UserId = userId, }, commandType: CommandType.StoredProcedure); diff --git a/src/Infrastructure.EntityFramework/NotificationCenter/Repositories/NotificationRepository.cs b/src/Infrastructure.EntityFramework/NotificationCenter/Repositories/NotificationRepository.cs index 6729a6f1fc..213a14a81d 100644 --- a/src/Infrastructure.EntityFramework/NotificationCenter/Repositories/NotificationRepository.cs +++ b/src/Infrastructure.EntityFramework/NotificationCenter/Repositories/NotificationRepository.cs @@ -75,7 +75,7 @@ public class NotificationRepository : Repository> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId) + public async Task> MarkNotificationsAsDeletedByTask(Guid taskId) { await using var scope = ServiceScopeFactory.CreateAsyncScope(); var dbContext = GetDatabaseContext(scope); @@ -87,7 +87,7 @@ public class NotificationRepository : Repository n.Id).ToList(); var statuses = await dbContext.Set() - .Where(ns => notificationIds.Contains(ns.NotificationId) && ns.UserId == userId) + .Where(ns => notificationIds.Contains(ns.NotificationId)) .ToListAsync(); var now = DateTime.UtcNow; @@ -103,12 +103,12 @@ public class NotificationRepository : Repository().Add(new NotificationStatus { NotificationId = notification.Id, - UserId = userId, + UserId = (Guid)notification.UserId, DeletedDate = now }); } diff --git a/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_MarkAsDeletedByTask.sql b/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_MarkAsDeletedByTask.sql index 6badf6821d..3cf2d4c668 100644 --- a/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_MarkAsDeletedByTask.sql +++ b/src/Sql/NotificationCenter/dbo/Stored Procedures/Notification_MarkAsDeletedByTask.sql @@ -1,6 +1,5 @@ CREATE PROCEDURE [dbo].[Notification_MarkAsDeletedByTask] - @TaskId UNIQUEIDENTIFIER, - @UserId UNIQUEIDENTIFIER + @TaskId UNIQUEIDENTIFIER AS BEGIN SET NOCOUNT ON; @@ -17,16 +16,15 @@ BEGIN FROM NotificationStatus ns INNER JOIN Notification n ON ns.NotificationId = n.Id WHERE n.TaskId = @TaskId - AND ns.UserId = @UserId AND ns.DeletedDate IS NULL; -- Insert NotificationStatus records for notifications that don't have one yet INSERT INTO NotificationStatus (NotificationId, UserId, DeletedDate) OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications - SELECT n.Id, @UserId, GETUTCDATE() + SELECT n.Id, n.UserId, GETUTCDATE() FROM Notification n LEFT JOIN NotificationStatus ns - ON n.Id = ns.NotificationId AND ns.UserId = @UserId + ON n.Id = ns.NotificationId WHERE n.TaskId = @TaskId AND ns.NotificationId IS NULL; diff --git a/util/Migrator/DbScripts/2025-05-30_00_Notification_MarkAsDeletedByTask.sql b/util/Migrator/DbScripts/2025-05-30_00_Notification_MarkAsDeletedByTask.sql index fcf758605b..e4e6ed7d21 100644 --- a/util/Migrator/DbScripts/2025-05-30_00_Notification_MarkAsDeletedByTask.sql +++ b/util/Migrator/DbScripts/2025-05-30_00_Notification_MarkAsDeletedByTask.sql @@ -1,6 +1,5 @@ CREATE OR ALTER PROCEDURE [dbo].[Notification_MarkAsDeletedByTask] - @TaskId UNIQUEIDENTIFIER, - @UserId UNIQUEIDENTIFIER + @TaskId UNIQUEIDENTIFIER AS BEGIN SET NOCOUNT ON; @@ -17,16 +16,15 @@ BEGIN FROM NotificationStatus ns INNER JOIN Notification n ON ns.NotificationId = n.Id WHERE n.TaskId = @TaskId - AND ns.UserId = @UserId AND ns.DeletedDate IS NULL; -- Insert NotificationStatus records for notifications that don't have one yet INSERT INTO NotificationStatus (NotificationId, UserId, DeletedDate) OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications - SELECT n.Id, @UserId, GETUTCDATE() + SELECT n.Id, n.UserId, GETUTCDATE() FROM Notification n LEFT JOIN NotificationStatus ns - ON n.Id = ns.NotificationId AND ns.UserId = @UserId + ON n.Id = ns.NotificationId WHERE n.TaskId = @TaskId AND ns.NotificationId IS NULL;