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.
/// </summary>
/// <param name="taskId">The unique identifier of the task.</param>
/// <param name="userId">User Id</param>
/// <returns>
/// A collection of users ids for the notifications that are now marked as deleted.
/// </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.
/// </summary>
/// <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>
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.
var uniqueUserIds = userIds.Distinct();

View File

@ -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);
}
}

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);
@ -66,7 +66,6 @@ public class NotificationRepository : Repository<Notification, Guid>, INotificat
new
{
TaskId = taskId,
UserId = userId,
},
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();
var dbContext = GetDatabaseContext(scope);
@ -87,7 +87,7 @@ public class NotificationRepository : Repository<Core.NotificationCenter.Entitie
var notificationIds = notifications.Select(n => n.Id).ToList();
var statuses = await dbContext.Set<NotificationStatus>()
.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<Core.NotificationCenter.Entitie
status.DeletedDate = now;
}
}
else
else if (notification.UserId.HasValue)
{
dbContext.Set<NotificationStatus>().Add(new NotificationStatus
{
NotificationId = notification.Id,
UserId = userId,
UserId = (Guid)notification.UserId,
DeletedDate = now
});
}

View File

@ -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;

View File

@ -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;