mirror of
https://github.com/bitwarden/server.git
synced 2025-07-21 17:41:40 -05:00
Refactor PendingSecurityTasks
to RefreshSecurityTasks
(#5903)
- Allows for more general use case of security task notifications
This commit is contained in:
@ -31,5 +31,5 @@ public enum PushType : byte
|
|||||||
Notification = 20,
|
Notification = 20,
|
||||||
NotificationStatus = 21,
|
NotificationStatus = 21,
|
||||||
|
|
||||||
PendingSecurityTasks = 22
|
RefreshSecurityTasks = 22
|
||||||
}
|
}
|
||||||
|
@ -389,10 +389,10 @@ public interface IPushNotificationService
|
|||||||
ExcludeCurrentContext = false,
|
ExcludeCurrentContext = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
Task PushPendingSecurityTasksAsync(Guid userId)
|
Task PushRefreshSecurityTasksAsync(Guid userId)
|
||||||
=> PushAsync(new PushNotification<UserPushNotification>
|
=> PushAsync(new PushNotification<UserPushNotification>
|
||||||
{
|
{
|
||||||
Type = PushType.PendingSecurityTasks,
|
Type = PushType.RefreshSecurityTasks,
|
||||||
Target = NotificationTarget.User,
|
Target = NotificationTarget.User,
|
||||||
TargetId = userId,
|
TargetId = userId,
|
||||||
Payload = new UserPushNotification
|
Payload = new UserPushNotification
|
||||||
|
@ -89,7 +89,7 @@ public class CreateManyTaskNotificationsCommand : ICreateManyTaskNotificationsCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Notify the user that they have pending security tasks
|
// Notify the user that they have pending security tasks
|
||||||
await _pushNotificationService.PushPendingSecurityTasksAsync(userId);
|
await _pushNotificationService.PushRefreshSecurityTasksAsync(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class MarkNotificationsForTaskAsDeletedCommand : IMarkNotificationsForTas
|
|||||||
var uniqueUserIds = userIds.Distinct();
|
var uniqueUserIds = userIds.Distinct();
|
||||||
foreach (var id in uniqueUserIds)
|
foreach (var id in uniqueUserIds)
|
||||||
{
|
{
|
||||||
await _pushNotificationService.PushPendingSecurityTasksAsync(id);
|
await _pushNotificationService.PushRefreshSecurityTasksAsync(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ public static class HubHelpers
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case PushType.PendingSecurityTasks:
|
case PushType.RefreshSecurityTasks:
|
||||||
var pendingTasksData = JsonSerializer.Deserialize<PushNotificationData<UserPushNotification>>(notificationJson, _deserializerOptions);
|
var pendingTasksData = JsonSerializer.Deserialize<PushNotificationData<UserPushNotification>>(notificationJson, _deserializerOptions);
|
||||||
await hubContext.Clients.User(pendingTasksData.Payload.UserId.ToString())
|
await hubContext.Clients.User(pendingTasksData.Payload.UserId.ToString())
|
||||||
.SendAsync(_receiveMessageMethod, pendingTasksData, cancellationToken);
|
.SendAsync(_receiveMessageMethod, pendingTasksData, cancellationToken);
|
||||||
|
@ -166,7 +166,7 @@ public class PushControllerTests
|
|||||||
yield return UserTyped(PushType.SyncOrgKeys);
|
yield return UserTyped(PushType.SyncOrgKeys);
|
||||||
yield return UserTyped(PushType.SyncSettings);
|
yield return UserTyped(PushType.SyncSettings);
|
||||||
yield return UserTyped(PushType.LogOut);
|
yield return UserTyped(PushType.LogOut);
|
||||||
yield return UserTyped(PushType.PendingSecurityTasks);
|
yield return UserTyped(PushType.RefreshSecurityTasks);
|
||||||
|
|
||||||
yield return Typed(new PushSendRequestModel<AuthRequestPushNotification>
|
yield return Typed(new PushSendRequestModel<AuthRequestPushNotification>
|
||||||
{
|
{
|
||||||
|
@ -707,7 +707,7 @@ public class AzureQueuePushNotificationServiceTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PushPendingSecurityTasksAsync_SendsExpectedResponse()
|
public async Task PushRefreshSecurityTasksAsync_SendsExpectedResponse()
|
||||||
{
|
{
|
||||||
var userId = Guid.NewGuid();
|
var userId = Guid.NewGuid();
|
||||||
|
|
||||||
@ -722,7 +722,7 @@ public class AzureQueuePushNotificationServiceTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
await VerifyNotificationAsync(
|
await VerifyNotificationAsync(
|
||||||
async sut => await sut.PushPendingSecurityTasksAsync(userId),
|
async sut => await sut.PushRefreshSecurityTasksAsync(userId),
|
||||||
expectedPayload
|
expectedPayload
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -368,7 +368,7 @@ public class NotificationsApiPushNotificationServiceTests : PushTestBase
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override JsonNode GetPushPendingSecurityTasksResponsePayload(Guid userId)
|
protected override JsonNode GetPushRefreshSecurityTasksResponsePayload(Guid userId)
|
||||||
{
|
{
|
||||||
return new JsonObject
|
return new JsonObject
|
||||||
{
|
{
|
||||||
|
@ -93,7 +93,7 @@ public abstract class PushTestBase
|
|||||||
protected abstract JsonNode GetPushNotificationStatusResponsePayload(Notification notification, NotificationStatus notificationStatus, Guid? userId, Guid? organizationId);
|
protected abstract JsonNode GetPushNotificationStatusResponsePayload(Notification notification, NotificationStatus notificationStatus, Guid? userId, Guid? organizationId);
|
||||||
protected abstract JsonNode GetPushSyncOrganizationStatusResponsePayload(Organization organization);
|
protected abstract JsonNode GetPushSyncOrganizationStatusResponsePayload(Organization organization);
|
||||||
protected abstract JsonNode GetPushSyncOrganizationCollectionManagementSettingsResponsePayload(Organization organization);
|
protected abstract JsonNode GetPushSyncOrganizationCollectionManagementSettingsResponsePayload(Organization organization);
|
||||||
protected abstract JsonNode GetPushPendingSecurityTasksResponsePayload(Guid userId);
|
protected abstract JsonNode GetPushRefreshSecurityTasksResponsePayload(Guid userId);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PushSyncCipherCreateAsync_SendsExpectedResponse()
|
public async Task PushSyncCipherCreateAsync_SendsExpectedResponse()
|
||||||
@ -444,13 +444,13 @@ public abstract class PushTestBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task PushPendingSecurityTasksAsync_SendsExpectedResponse()
|
public async Task PushRefreshSecurityTasksAsync_SendsExpectedResponse()
|
||||||
{
|
{
|
||||||
var userId = Guid.NewGuid();
|
var userId = Guid.NewGuid();
|
||||||
|
|
||||||
await VerifyNotificationAsync(
|
await VerifyNotificationAsync(
|
||||||
async sut => await sut.PushPendingSecurityTasksAsync(userId),
|
async sut => await sut.PushRefreshSecurityTasksAsync(userId),
|
||||||
GetPushPendingSecurityTasksResponsePayload(userId)
|
GetPushRefreshSecurityTasksResponsePayload(userId)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,7 +491,7 @@ public class RelayPushNotificationServiceTests : PushTestBase
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override JsonNode GetPushPendingSecurityTasksResponsePayload(Guid userId)
|
protected override JsonNode GetPushRefreshSecurityTasksResponsePayload(Guid userId)
|
||||||
{
|
{
|
||||||
return new JsonObject
|
return new JsonObject
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user