1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-08 20:20:32 -05:00

omit userId from MarkTaskAsCompletedCommand query.

The userId from the notification will be used
This commit is contained in:
Nick Krantz 2025-06-01 20:19:57 -05:00
parent 8d40d66e63
commit 06f9f156f6
No known key found for this signature in database
GPG Key ID: FF670021ABCAB82E
8 changed files with 16 additions and 23 deletions

View File

@ -37,9 +37,8 @@ public interface INotificationRepository : IRepository<Notification, Guid>
/// Marks notifications as deleted by a task Id. /// Marks notifications as deleted by a task Id.
/// </summary> /// </summary>
/// <param name="taskId">The unique identifier of the task.</param> /// <param name="taskId">The unique identifier of the task.</param>
/// <param name="userId">User Id</param>
/// <returns> /// <returns>
/// A collection of users ids for the notifications that are now marked as deleted. /// A collection of users ids for the notifications that are now marked as deleted.
/// </returns> /// </returns>
Task<IEnumerable<Guid>> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId); Task<IEnumerable<Guid>> MarkNotificationsAsDeletedByTask(Guid taskId);
} }

View File

@ -6,7 +6,6 @@ public interface IMarkNotificationsForTaskAsDeletedCommand
/// Marks notifications associated with a given taskId as deleted. /// Marks notifications associated with a given taskId as deleted.
/// </summary> /// </summary>
/// <param name="taskId">The unique identifier of the task to complete</param> /// <param name="taskId">The unique identifier of the task to complete</param>
/// <param name="userId">User Id</param>
/// <returns>A task representing the async operation</returns> /// <returns>A task representing the async operation</returns>
Task MarkAsDeletedAsync(Guid taskId, Guid userId); Task MarkAsDeletedAsync(Guid taskId);
} }

View File

@ -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. // For each user associated with the notifications, send a push notification so local tasks can be updated.
var uniqueUserIds = userIds.Distinct(); var uniqueUserIds = userIds.Distinct();

View File

@ -52,6 +52,6 @@ public class MarkTaskAsCompletedCommand : IMarkTaskAsCompleteCommand
await _securityTaskRepository.ReplaceAsync(task); await _securityTaskRepository.ReplaceAsync(task);
// Mark all notifications related to this task as deleted // Mark all notifications related to this task as deleted
await _markNotificationsForTaskAsDeletedAsync.MarkAsDeletedAsync(taskId, _currentContext.UserId.Value); await _markNotificationsForTaskAsDeletedAsync.MarkAsDeletedAsync(taskId);
} }
} }

View File

@ -57,7 +57,7 @@ public class NotificationRepository : Repository<Notification, Guid>, INotificat
}; };
} }
public async Task<IEnumerable<Guid>> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId) public async Task<IEnumerable<Guid>> MarkNotificationsAsDeletedByTask(Guid taskId)
{ {
await using var connection = new SqlConnection(ConnectionString); await using var connection = new SqlConnection(ConnectionString);
@ -66,7 +66,6 @@ public class NotificationRepository : Repository<Notification, Guid>, INotificat
new new
{ {
TaskId = taskId, TaskId = taskId,
UserId = userId,
}, },
commandType: CommandType.StoredProcedure); commandType: CommandType.StoredProcedure);

View File

@ -75,7 +75,7 @@ public class NotificationRepository : Repository<Core.NotificationCenter.Entitie
}; };
} }
public async Task<IEnumerable<Guid>> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId) public async Task<IEnumerable<Guid>> MarkNotificationsAsDeletedByTask(Guid taskId)
{ {
await using var scope = ServiceScopeFactory.CreateAsyncScope(); await using var scope = ServiceScopeFactory.CreateAsyncScope();
var dbContext = GetDatabaseContext(scope); var dbContext = GetDatabaseContext(scope);
@ -87,7 +87,7 @@ public class NotificationRepository : Repository<Core.NotificationCenter.Entitie
var notificationIds = notifications.Select(n => n.Id).ToList(); var notificationIds = notifications.Select(n => n.Id).ToList();
var statuses = await dbContext.Set<NotificationStatus>() var statuses = await dbContext.Set<NotificationStatus>()
.Where(ns => notificationIds.Contains(ns.NotificationId) && ns.UserId == userId) .Where(ns => notificationIds.Contains(ns.NotificationId))
.ToListAsync(); .ToListAsync();
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
@ -103,12 +103,12 @@ public class NotificationRepository : Repository<Core.NotificationCenter.Entitie
status.DeletedDate = now; status.DeletedDate = now;
} }
} }
else else if (notification.UserId.HasValue)
{ {
dbContext.Set<NotificationStatus>().Add(new NotificationStatus dbContext.Set<NotificationStatus>().Add(new NotificationStatus
{ {
NotificationId = notification.Id, NotificationId = notification.Id,
UserId = userId, UserId = (Guid)notification.UserId,
DeletedDate = now DeletedDate = now
}); });
} }

View File

@ -1,6 +1,5 @@
CREATE PROCEDURE [dbo].[Notification_MarkAsDeletedByTask] CREATE PROCEDURE [dbo].[Notification_MarkAsDeletedByTask]
@TaskId UNIQUEIDENTIFIER, @TaskId UNIQUEIDENTIFIER
@UserId UNIQUEIDENTIFIER
AS AS
BEGIN BEGIN
SET NOCOUNT ON; SET NOCOUNT ON;
@ -17,16 +16,15 @@ BEGIN
FROM NotificationStatus ns FROM NotificationStatus ns
INNER JOIN Notification n ON ns.NotificationId = n.Id INNER JOIN Notification n ON ns.NotificationId = n.Id
WHERE n.TaskId = @TaskId WHERE n.TaskId = @TaskId
AND ns.UserId = @UserId
AND ns.DeletedDate IS NULL; AND ns.DeletedDate IS NULL;
-- Insert NotificationStatus records for notifications that don't have one yet -- Insert NotificationStatus records for notifications that don't have one yet
INSERT INTO NotificationStatus (NotificationId, UserId, DeletedDate) INSERT INTO NotificationStatus (NotificationId, UserId, DeletedDate)
OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications
SELECT n.Id, @UserId, GETUTCDATE() SELECT n.Id, n.UserId, GETUTCDATE()
FROM Notification n FROM Notification n
LEFT JOIN NotificationStatus ns LEFT JOIN NotificationStatus ns
ON n.Id = ns.NotificationId AND ns.UserId = @UserId ON n.Id = ns.NotificationId
WHERE n.TaskId = @TaskId WHERE n.TaskId = @TaskId
AND ns.NotificationId IS NULL; AND ns.NotificationId IS NULL;

View File

@ -1,6 +1,5 @@
CREATE OR ALTER PROCEDURE [dbo].[Notification_MarkAsDeletedByTask] CREATE OR ALTER PROCEDURE [dbo].[Notification_MarkAsDeletedByTask]
@TaskId UNIQUEIDENTIFIER, @TaskId UNIQUEIDENTIFIER
@UserId UNIQUEIDENTIFIER
AS AS
BEGIN BEGIN
SET NOCOUNT ON; SET NOCOUNT ON;
@ -17,16 +16,15 @@ BEGIN
FROM NotificationStatus ns FROM NotificationStatus ns
INNER JOIN Notification n ON ns.NotificationId = n.Id INNER JOIN Notification n ON ns.NotificationId = n.Id
WHERE n.TaskId = @TaskId WHERE n.TaskId = @TaskId
AND ns.UserId = @UserId
AND ns.DeletedDate IS NULL; AND ns.DeletedDate IS NULL;
-- Insert NotificationStatus records for notifications that don't have one yet -- Insert NotificationStatus records for notifications that don't have one yet
INSERT INTO NotificationStatus (NotificationId, UserId, DeletedDate) INSERT INTO NotificationStatus (NotificationId, UserId, DeletedDate)
OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications
SELECT n.Id, @UserId, GETUTCDATE() SELECT n.Id, n.UserId, GETUTCDATE()
FROM Notification n FROM Notification n
LEFT JOIN NotificationStatus ns LEFT JOIN NotificationStatus ns
ON n.Id = ns.NotificationId AND ns.UserId = @UserId ON n.Id = ns.NotificationId
WHERE n.TaskId = @TaskId WHERE n.TaskId = @TaskId
AND ns.NotificationId IS NULL; AND ns.NotificationId IS NULL;