mirror of
https://github.com/bitwarden/server.git
synced 2025-06-07 19:50:32 -05:00
Only return UserIds from db layer
This commit is contained in:
parent
928bad3d0f
commit
8d40d66e63
@ -39,7 +39,7 @@ public interface INotificationRepository : IRepository<Notification, Guid>
|
|||||||
/// <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>
|
/// <param name="userId">User Id</param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A collection of notifications associated with the task that are now marked as deleted.
|
/// A collection of users ids for the notifications that are now marked as deleted.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
Task<IEnumerable<Notification>> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId);
|
Task<IEnumerable<Guid>> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId);
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,13 @@ public class MarkNotificationsForTaskAsDeletedCommand : IMarkNotificationsForTas
|
|||||||
|
|
||||||
public async Task MarkAsDeletedAsync(Guid taskId, Guid userId)
|
public async Task MarkAsDeletedAsync(Guid taskId, Guid userId)
|
||||||
{
|
{
|
||||||
var notifications = await _notificationRepository.MarkNotificationsAsDeletedByTask(taskId, userId);
|
var userIds = await _notificationRepository.MarkNotificationsAsDeletedByTask(taskId, userId);
|
||||||
|
|
||||||
// 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 = notifications.Select(n => n.UserId).Where(u => u.HasValue).Distinct();
|
var uniqueUserIds = userIds.Distinct();
|
||||||
foreach (var id in uniqueUserIds)
|
foreach (var id in uniqueUserIds)
|
||||||
{
|
{
|
||||||
await _pushNotificationService.PushPendingSecurityTasksAsync((Guid)id);
|
await _pushNotificationService.PushPendingSecurityTasksAsync(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,11 +57,11 @@ public class NotificationRepository : Repository<Notification, Guid>, INotificat
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<Notification>> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId)
|
public async Task<IEnumerable<Guid>> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId)
|
||||||
{
|
{
|
||||||
await using var connection = new SqlConnection(ConnectionString);
|
await using var connection = new SqlConnection(ConnectionString);
|
||||||
|
|
||||||
var results = await connection.QueryAsync<Notification>(
|
var results = await connection.QueryAsync<Guid>(
|
||||||
"[dbo].[Notification_MarkAsDeletedByTask]",
|
"[dbo].[Notification_MarkAsDeletedByTask]",
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
|
@ -75,7 +75,7 @@ public class NotificationRepository : Repository<Core.NotificationCenter.Entitie
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<Core.NotificationCenter.Entities.Notification>> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId)
|
public async Task<IEnumerable<Guid>> MarkNotificationsAsDeletedByTask(Guid taskId, Guid userId)
|
||||||
{
|
{
|
||||||
await using var scope = ServiceScopeFactory.CreateAsyncScope();
|
await using var scope = ServiceScopeFactory.CreateAsyncScope();
|
||||||
var dbContext = GetDatabaseContext(scope);
|
var dbContext = GetDatabaseContext(scope);
|
||||||
@ -116,6 +116,11 @@ public class NotificationRepository : Repository<Core.NotificationCenter.Entitie
|
|||||||
|
|
||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
return notifications;
|
var userIds = notifications
|
||||||
|
.Select(n => n.UserId)
|
||||||
|
.Where(u => u.HasValue)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return (IEnumerable<Guid>)userIds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,14 @@ BEGIN
|
|||||||
SET NOCOUNT ON;
|
SET NOCOUNT ON;
|
||||||
|
|
||||||
-- Collect NotificationIds as they are altered
|
-- Collect NotificationIds as they are altered
|
||||||
DECLARE @AlteredNotifications TABLE (
|
DECLARE @UserIdsForAlteredNotifications TABLE (
|
||||||
NotificationId UNIQUEIDENTIFIER
|
UserId UNIQUEIDENTIFIER
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Update existing NotificationStatus as deleted
|
-- Update existing NotificationStatus as deleted
|
||||||
UPDATE ns
|
UPDATE ns
|
||||||
SET ns.DeletedDate = GETUTCDATE()
|
SET ns.DeletedDate = GETUTCDATE()
|
||||||
OUTPUT inserted.NotificationId INTO @AlteredNotifications
|
OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications
|
||||||
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
|
||||||
@ -22,7 +22,7 @@ BEGIN
|
|||||||
|
|
||||||
-- 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.NotificationId INTO @AlteredNotifications
|
OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications
|
||||||
SELECT n.Id, @UserId, GETUTCDATE()
|
SELECT n.Id, @UserId, GETUTCDATE()
|
||||||
FROM Notification n
|
FROM Notification n
|
||||||
LEFT JOIN NotificationStatus ns
|
LEFT JOIN NotificationStatus ns
|
||||||
@ -30,9 +30,8 @@ BEGIN
|
|||||||
WHERE n.TaskId = @TaskId
|
WHERE n.TaskId = @TaskId
|
||||||
AND ns.NotificationId IS NULL;
|
AND ns.NotificationId IS NULL;
|
||||||
|
|
||||||
-- Return all notifications that have been altered
|
-- Return the user ids associated with the altered notifications
|
||||||
SELECT n.*
|
SELECT u.UserId
|
||||||
FROM Notification n
|
FROM @UserIdsForAlteredNotifications u;
|
||||||
INNER JOIN @AlteredNotifications a ON n.Id = a.NotificationId;
|
|
||||||
END
|
END
|
||||||
GO
|
GO
|
||||||
|
@ -6,14 +6,14 @@ BEGIN
|
|||||||
SET NOCOUNT ON;
|
SET NOCOUNT ON;
|
||||||
|
|
||||||
-- Collect NotificationIds as they are altered
|
-- Collect NotificationIds as they are altered
|
||||||
DECLARE @AlteredNotifications TABLE (
|
DECLARE @UserIdsForAlteredNotifications TABLE (
|
||||||
NotificationId UNIQUEIDENTIFIER
|
UserId UNIQUEIDENTIFIER
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Update existing NotificationStatus as deleted
|
-- Update existing NotificationStatus as deleted
|
||||||
UPDATE ns
|
UPDATE ns
|
||||||
SET ns.DeletedDate = GETUTCDATE()
|
SET ns.DeletedDate = GETUTCDATE()
|
||||||
OUTPUT inserted.NotificationId INTO @AlteredNotifications
|
OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications
|
||||||
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
|
||||||
@ -22,7 +22,7 @@ BEGIN
|
|||||||
|
|
||||||
-- 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.NotificationId INTO @AlteredNotifications
|
OUTPUT inserted.UserId INTO @UserIdsForAlteredNotifications
|
||||||
SELECT n.Id, @UserId, GETUTCDATE()
|
SELECT n.Id, @UserId, GETUTCDATE()
|
||||||
FROM Notification n
|
FROM Notification n
|
||||||
LEFT JOIN NotificationStatus ns
|
LEFT JOIN NotificationStatus ns
|
||||||
@ -30,9 +30,8 @@ BEGIN
|
|||||||
WHERE n.TaskId = @TaskId
|
WHERE n.TaskId = @TaskId
|
||||||
AND ns.NotificationId IS NULL;
|
AND ns.NotificationId IS NULL;
|
||||||
|
|
||||||
-- Return all notifications that have been altered
|
-- Return the user ids associated with the altered notifications
|
||||||
SELECT n.*
|
SELECT u.UserId
|
||||||
FROM Notification n
|
FROM @UserIdsForAlteredNotifications u;
|
||||||
INNER JOIN @AlteredNotifications a ON n.Id = a.NotificationId;
|
|
||||||
END
|
END
|
||||||
GO
|
GO
|
Loading…
x
Reference in New Issue
Block a user